在 ZSh 中找不到 Anaconda?

Anaconda not found in ZSh?

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

如果我在 bash,我可以打开和使用 anaconda,如笔记本、ipython 等

如果我将 shell 更改为 ZSH,所有 anaconda 命令都会显示为 "not found"。

如何让它在 zsh 中工作?

我使用 Mac 和 OSx Sierra。

提前致谢,

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

你也可以check this out from http://unix.stackexchange.com

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

我遇到了类似的问题。

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

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

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

conda 4.4.0 (released 2017-12-20), the recommended way to add conda to your PATH has changed. Instead of the approach described , this should be done using the conda.sh script 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.

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

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

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

跟进@m00am 的回答,从 Anaconda 4.5.11 开始,Anaconda 添加到 .bashrcbash 代码似乎 运行 在 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 <<<

这在我的 macOS 上对我有用

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


打开 .bash_profile 文件使用:

open ~/.bash_profile

anaconda 安装程序在文件末尾添加了一段代码。复制那个。

我的看起来像这样:

# 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 <<<

现在打开您的 .zshrc 文件:

open ~/.zshrc

将复制的代码粘贴到最后并保存。然后 运行 下面的命令,

source ~/.zshrc

在 iterm2 或终端上,你应该会看到 (base) 弹出

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

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

现在我打开.zshrc文件,把上面这句话加进去,就可以了。

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

如果您使用 2019.03 版本的 Anaconda,您可以将 .zshrc 文件更新为

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

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

升级到 Catalina 后

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

open ~/.bash_profile

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

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

我是这样解决的:

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

2) 我改成 zsh,anaconda 工作了。我不知道为什么,但我觉得你可以试试。

虽然我无法在 Mac 上测试它,(我安装了 Linux Zsh)这也适用于您:只需执行

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

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

在 .bashrc 中

zsh

在.zshrc

conda activate base

所有出口应该得到解决

only if you do not use chsh

来自他们的文档(这对我有用):如果您使用的是 macOS Catalina,新的默认 shell 是 zsh。您需要 运行 source <path to conda>/bin/activate 后跟 conda init zsh.

对于我的特定安装(通过双击安装程序完成),这最终是 source /opt/anaconda3/bin/activate

如果您因为将 macOS 从 Sierra 升级到 Catalina 而将终端从 bash 更改为 zsh 之后无意中发现了这里,那么对 Sebastian Thees 的回答稍作改动就可以解决问题。

首先,用

切换回bash
chsh -s /bin/bash

您的旧 conda 环境都非常活跃。然后,使用

在 zsh 上激活 conda
conda init zsh

最后切换回 zsh

chsh -s /bin/zsh

用这种方式跟踪你的 conda 安装文件夹不用大惊小怪,这对像我这样没有记忆力的人来说是一个加分项。

直接来自 Anaconda Installation Documentation:

如果您使用的是 macOS Catalina,新的默认 shell 是 zsh。您将需要 运行:

source <path to conda>/bin/activate

其次是:

conda init zsh

不幸的是,由于某种原因,这仅在命令行安装部分中提到。如果您是从 GUI 安装的,您仍然需要这样做。