【问题标题】:How can I avoid typing the "source ~/.bash_profile" command in the terminal every time?如何避免每次在终端中输入“source ~/.bash_profile”命令?
【发布时间】:2019-12-17 19:34:40
【问题描述】:

我刚刚安装了 Anaconda。当我尝试运行命令时,比如说conda --version,我收到以下错误消息:

zsh: command not found: conda

当我输入时:

source ~/.bash_profile

一切正常:

conda --version

conda 4.8.0

但我每次启动终端时都必须输入命令。

我的 .bash_profile 如下所示:

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

我能做些什么来解决这个问题?

系统:macOS

【问题讨论】:

    标签: macos terminal anaconda


    【解决方案1】:

    source ~/.bash_profile 放入~/.zsh

    Bash 在初始化过程中加载 .bash_profile,对于 zsh 它是 .zsh

    macOS Catalina 的默认 shell 从 bash 更改为 zsh,这就是问题所在。

    【讨论】:

    • 感谢您的回答。 .zsh 文件不存在。所以我用 textedit 创建了它并将它保存在我的用户文件夹中。在文件中,我包含了命令。但是它不起作用。如果我尝试打开 .zsh 它仍然说它不存在。但我可以在我的文件中看到它。 open 命令适用于所有其他文件,例如 .bash_profile...
    • 你必须重启终端。确保 .zsh 文件与 .bash_profile 位于同一目录中。
    • 好的。我使用 vi 命令写入文件。我的 .zsh 看起来像这样: source ~/.bash_profile 但是这不起作用。它与我的 .bash_profile 位于同一文件夹中
    猜你喜欢
    • 2019-10-23
    • 2016-10-04
    • 2021-09-16
    • 2020-02-09
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    相关资源
    最近更新 更多