我最近在我的Mac上安装了anaconda2.默认情况下,Conda配置为在我打开新的终端会话时激活基本环境.
我想要访问Conda命令(即我希望Conda的路径添加到我的$ PATH,Conda在初始化时会这样做,这很好).
但我通常不用python编程,我不希望Conda默认激活环境.
当第一次conda init从提示执行时,Conda将以下内容添加到我的.bash_profile:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/geoff/anaconda2/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/geoff/anaconda2/etc/profile.d/conda.sh" ]; then
. "/Users/geoff/anaconda2/etc/profile.d/conda.sh"
else
export PATH="/Users/geoff/anaconda2/bin:$PATH"
fi
# fi
unset __conda_setup
# <<< conda initialize <<<
Run Code Online (Sandbox Code Playgroud)
如果我注释掉整个块,那么我就无法激活任何Conda环境.
我试图评论整个街区除外
export PATH="/Users/geoff/anaconda2/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
但是当我开始一个新会话并尝试激活一个环境时,我收到了以下错误消息:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. …Run Code Online (Sandbox Code Playgroud) 我在使用 brew 时遇到了 openssl 和 python@2 问题,这里已经解释了(未解决)。重新安装 Python 和 openssl 的文档化解决方法不起作用,所以我决定卸载并重新安装 Python。
问题是,当您尝试使用 brew 安装 Python 2 时,您会收到以下消息:
brew install python@2
Error: No available formula with the name "python@2"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow
python@2 was deleted from homebrew/core in commit 028f11f9e:
python@2: delete (https://github.com/Homebrew/homebrew-core/issues/49796)
EOL 1 January 2020.
We gave it 1 month more …Run Code Online (Sandbox Code Playgroud) 当使用anaconda(安装为python)时,当我切换到虚拟环境时:
source activate my_env
Run Code Online (Sandbox Code Playgroud)
它会改变我的提示并在我的PS1开头添加(my_env).
我已经尝试添加export VIRTUAL_ENV_DISABLE_PROMPT=1到我的bashrc,但它没有帮助.
任何的想法?
我的.bashrc:
# show a short way
shortwd() {
num_dirs=3
pwd_symbol="..."
newPWD="${PWD/#$HOME/~}"
if [ $(echo -n $newPWD | awk -F '/' '{print NF}') -gt $num_dirs ]; then
newPWD=$(echo -n $newPWD | awk -F '/' '{print $1 "/.../" $(NF-1) "/" $(NF)}')
fi
echo -n $newPWD
}
# show git branch
git_branch() {
git symbolic-ref HEAD --short
}
export PS1='\n$CONDA_PROMPT_MODIFIER\e[38;5;211m$(shortwd)\e[38;5;48m [$(git_branch)]\e[0m$'
Run Code Online (Sandbox Code Playgroud)
现在 bash 看起来像:
(基础)/.../MyCode/python [master]$
但在我跑去conda activate env切换我的 conda 环境之后。它有一个 BUG,无论我运行什么命令,总是在命令输出的末尾显示当前的 conda env 名称。如下所示:
(基础) /.../MyCode/python [master]$ls
code_study keras mxnet …