Python 在 ZSh 中找不到 Anaconda?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40370467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:27:10  来源:igfitidea点击:

Anaconda not found in ZSh?

pythonmacosipythonanacondazsh

提问by marz

I installed Anaconda via command line. The bash file.

我通过命令行安装了 Anaconda。bash 文件。

If Im in bash, I can open and use anaconda, like notebooks, ipython, etc.

如果我使用 bash,我可以打开并使用 anaconda,例如 notebooks、ipython 等。

If I change my shell to ZSH, all the anaconda commands appear like "not found".

如果我将 shell 更改为 ZSH,则所有 anaconda 命令都显示为“未找到”。

How I can make it work in zsh?

我怎样才能让它在 zsh 中工作?

I use a Mac with OSx Sierra.

我使用带有 OSx Sierra 的 Mac。

Thanks in advance,

提前致谢,

回答by Sebastian Thees

Altough I cannot test it on a Mac, (I have a Linux Zsh installed) this should work for you as well: Just execute

尽管我无法在 Mac 上对其进行测试,(我安装了 Linux Zsh)这也适用于您:只需执行

/(your conda installation path)/bin/conda init zsh

and restart your zsh shell. The init command will change your ~/.zshrc file accordingly, setting your PATH correctly and slightly change the PS1 (which is was most answers here do manually...).

并重新启动您的 zsh shell。init 命令将相应地更改您的 ~/.zshrc 文件,正确设置您的 PATH 并稍微更改 PS1(这是这里的大多数答案手动执行...)。

回答by Jonathan Wheeler

I had a similar issue.

我有一个类似的问题。

I checked in my .profile, .bashrc, and .bash_profiledot files in order to find any PATH information that I could copy over into my .zshrcfile. Sure enough:

我检查了我的.profile.bashrc.bash_profiledot 文件,以便找到可以复制到我的.zshrc文件中的任何 PATH 信息。果然:

# added by Miniconda3 4.2.12 installer
export PATH="/Users/username/miniconda3/bin:$PATH"

After running source ~/.zshrcwith those lines added, I could fire up my jupyter notebook server.

source ~/.zshrc添加这些行后运行,我可以启动我的 jupyter notebook 服务器。

回答by m00am

Since conda 4.4.0(released 2017-12-20), the recommended way to add conda to your PATH has changed. Instead of the approach described in Jonathan's answer, this should be done using the conda.shscript in the etc/profile.d/folder of your conda installation. After that you can activate the base environment. More information on why this is the case can be found in the conda changelog.

conda 4.4.0(2017 年 12 月 20 日发布)以来,将 conda 添加到 PATH 的推荐方法已更改。这应该使用conda 安装文件夹中的脚本来完成,而不是Jonathan's answer 中描述的方法。之后,您可以激活基础环境。有关为什么会出现这种情况的更多信息,请参阅 conda更改日志conda.shetc/profile.d/

I needed to add the following lines to my .zshrc:

我需要将以下行添加到我的.zshrc

.  ~/miniconda3/etc/profile.d/conda.sh
conda activate base

This assumes that (mini)conda was installed with default parameters, i.e. into the home folder.

这假设 (mini)conda 是使用默认参数安装的,即安装到主文件夹中。

回答by drevicko

Following up on @m00am's answer, as of Anaconda 4.5.11, the bashcode Anaconda adds to .bashrcseems to run perfectly well also in zsh, so copying that into your .zshrcworks well. In my case, the code looked like this:

对@ m00am的回答跟进,如蟒蛇4.5.11的,该bash代码巨蟒增加.bashrc似乎运行得很好也zsh,所以复制这到你.zshrc的作品好。就我而言,代码如下所示:

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

回答by Vincent Tang

This worked for me on my macOS

这在我的 macOS 上对我有用

https://medium.com/@sumitmenon/how-to-get-anaconda-to-work-with-oh-my-zsh-on-mac-os-x-7c1c7247d896

https://medium.com/@sumitmenon/how-to-get-anaconda-to-work-with-oh-my-zsh-on-mac-os-x-7c1c7247d896



Open the .bash_profile file using:

使用以下命令打开 .bash_profile 文件:

open ~/.bash_profile

There's a block of code the anaconda installer added to the end of the file. Copy that.

anaconda 安装程序在文件末尾添加了一段代码。收到。

Mine looks something like this:

我的看起来像这样:

# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

Now open your .zshrc file:

现在打开你的 .zshrc 文件:

open ~/.zshrc

Run

source ~/.zshrc

When on iterm2 or the terminal, you should see a (base)pop up in there

在 iterm2 或终端上时,您应该会(base)在其中看到一个弹出窗口

回答by abdullahselek

This solution worked for me on macOS Mojave

这个解决方案在 macOS Mojave 上对我有用

If you use version 2019.03of Anaconda you can update your .zshrcfile with

如果您使用2019.03Anaconda版本,则可以使用以下命令更新.zshrc文件

# Anaconda
. /anaconda3/etc/profile.d/conda.sh
conda activate base

after saving file don't forget to run source ~/.zshrc.

保存文件后不要忘记运行source ~/.zshrc.

After upgrading to Catalina

升级到 Catalina 后

If you install a new Anaconda3 2019.07 you can use solution below.

如果您安装新的 Anaconda3 2019.07,您可以使用以下解决方案。

open ~/.bash_profile

Copy the line starts with # added by Anaconda3 2019.07 installerand ends with # <<< conda init <<<and paste into .zshrc. Then run source ~/.zshrc.

复制以开头# added by Anaconda3 2019.07 installer和结尾的行# <<< conda init <<<并粘贴到.zshrc. 然后运行source ~/.zshrc

回答by Pete Hornsby

You need to set your path variable for the ZSH environment. The easy way to do this would be to set your path variable in your .zshrc file to include the location of Anaconda. To get the path in your bash terminal type which anaconda

您需要为 ZSH 环境设置路径变量。执行此操作的简单方法是在 .zshrc 文件中设置路径变量以包含 Anaconda 的位置。获取 bash 终端类型中的路径which anaconda

You can also checkthis out from http://unix.stackexchange.com

您也可以从http://unix.stackexchange.com查看

Zsh/Bash startup files loading order (.bashrc, .zshrc etc.)

Zsh/Bash 启动文件加载顺序(.bashrc、.zshrc 等)

回答by u10776698

I had a similar issue after I installed anaconda3 in ubuntu.

在 ubuntu 中安装 anaconda3后,我遇到了类似的问题。

This is how I solved it:

我是这样解决的:

1) I changed to bash and anaconda can work

1)我改成bash,anaconda就可以工作了

2) I changed to zsh, and anaconda works. I don't know why, but I think you can try.

2)我改成zsh,anaconda就可以了。我不知道为什么,但我想你可以试试。

回答by Haoyu Guo

in my original profile, which is .bash_profile, it looks like this:

在我的原始配置文件中,即 .bash_profile,它看起来像这样:

### added by Anaconda3 4.4.0 installer
export PATH="/Users/myname/anaconda/bin:$PATH"

and now i open the file .zshrc, add the sentence above to it, it goes all right now.

现在我打开文件 .zshrc,将上面的句子添加到其中,现在一切正常。

回答by azamat alibaev

In .bashrc

在 .bashrc 中

zsh

In .zshrc

在 .zshrc 中

conda activate base

all exportsshould be resolved

所有出口都应该解决

only if you do not use chsh

仅当您不使用chsh 时