例如服务器上有py3.6.8这个conda虚拟环境,现在需要激活该环境,
使用的激活命令为 source activate py3.6.8
或 conda activate py3.6.8
,有一个注意事项,见注意,去激活命令为 source deactivate
或conda deactivate
命令。
1. 相关配置
不过上述命令比较长,每次都输入这么多,太花时间,所以可以使用如下的alias
命令进行设置。
在 ~/.bashrc 或 ~/.zshrc 配置文件中添加上如下语句,即可。我使用的是zsh,所以这里修改 ~/.zshrc
#设置conda环境快捷键 -2019年12月12日21:09:02
#激活conda环境,必须使用先使用source命令,之后使用conda,或者直接source activate version启动
alias activate='foo(){source activate "$1";};foo'
alias act='source activate'
alias deact='conda deactivate'
alias deactivate='conda deactivate'
#added end
设置完成再使用source ~/.zshrc
,即可生效。
2. other
-
上面命令中用到了
alias activate='foo(){source activate "$1";};foo'
。我理解的是相当于一个函数,暂未深究。 -
注意:在Linux、Mac下不能一开始就使用
conda activate py3.6.8
命令,否则会出现提示:CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. If your shell is Bash or a Bourne variant, enable conda for the current user with $ echo ". /usr/local/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc or, for all users, enable conda with $ sudo ln -s /usr/local/anaconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh The options above will permanently enable the 'conda' command, but they do NOT put conda's base (root) environment on PATH. To do so, run $ conda activate in your terminal, or to put the base environment on PATH permanently, run $ echo "conda activate" >> ~/.bashrc Previous to conda 4.4, the recommended way to activate conda was to modify PATH in your ~/.bashrc file. You should manually remove the line that looks like export PATH="/usr/local/anaconda3/bin:$PATH" ^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^
截图更好看: