从 MATLAB 调用 Anaconda 环境:未找到 Conda 命令 [英] Calling An Anaconda Environment from MATLAB: Conda Command Not Found

查看:74
本文介绍了从 MATLAB 调用 Anaconda 环境:未找到 Conda 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用我在自己的 Anaconda 环境中创建的 Python 脚本,并想从 Matlab 2020a 调用该脚本.但是,当我尝试从 Matlab 激活环境时,收到一条错误消息:

I want to call a Python script I created in its own Anaconda environment and wanted to call the script from Matlab 2020a. However, when I try to activate the environment from Matlab, I get an error message:

system('conda activate *name_of_environment*')
/bin/bash: conda: command not found

我在 Ubuntu 18.04 机器上安装了最新版本的 anaconda3 (2020.02),并且按照建议,没有将 conda 添加到 bashrc,而是按照建议添加了 conda.sh 目录 此处:

I installed the newest version of anaconda3 (2020.02) on a Ubuntu 18.04 machine and, as recommended, didn't add conda to bashrc but added the conda.sh directory instead as recommended here:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/michael/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/michael/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/michael/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/michael/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

# export PATH="/home/michael/anaconda3/bin:$PATH"  # commented out by conda initialize

#Enable conda to be called from bash
source /home/michael/anaconda3/etc/profile.d

但是,我找不到如何从 Matlab 运行 conda 的解释.我错过了什么吗?

However, I can't find an explanation how to run conda from Matlab otherwise. Am I missing something?

非常感谢,最好,

迈克尔

推荐答案

让我在答案中详细说明我的评论.

Let me elaborate my comment it in an answer.

通过 PATH 环境变量找到二进制文件.conda 的位置不在该变量中.因此,您应该将其添加到您的 PATH 变量中(或在您的通知中取消对该脚本的注释).

Binaries are found trough the PATH environment variables. The location of conda is not in that variable. Therefore you should either add it to your PATH variables (or un-comment it that script at your notification).

示例:

$ export PATH="$PATH:/home/michael/anaconda3/bin/"
$ ./yourscript.sh

但也可能是 PATH 变量不是通过 system() 复制的,我猜它是在新的 shell 中执行脚本.在这种情况下,您应该将其执行为:

But it also can be that the PATH variable isn't copied through system(), which I guess executes the script in a new shell. In this case, you should execute it as:

system('/home/michael/anaconda3/bin/conda activate *name_of_environment*')

这篇关于从 MATLAB 调用 Anaconda 环境:未找到 Conda 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆