Can't execute `conda activate` from bash script
程序员文章站
2022-06-01 20:15:36
...
参考链接:
https://github.com/conda/conda/issues/7980
https://github.com/conda/conda/blob/master/CHANGELOG.md#440-2017-12-20
使用anaconda3创建新的环境,新的**和激死?方式如下:
To activate this environment, use
$ conda activate 环境名称
To deactivate an active environment, use
$ conda deactivate
但是如果你的anaconda是从一个老版本更新的,$ conda activate 环境名称 会出现如下问题:
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 ". ~/anaconda/etc/profile.d/conda.sh" >> ~/.bash_profile
or, for all users, enable conda with
$ sudo ln -s ~/anaconda/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" >> ~/.bash_profile
Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bash_profile file. You should manually remove the line that looks like
export PATH="~/anaconda/bin:$PATH"
^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^
conda info 获得如下结果:
active environment : None
shell level : 0
user config file : /home/wunan/.condarc
populated config files :
conda version : 4.5.11
conda-build version : 2.0.2
python version : 3.5.5.final.0
base environment : /home/wunan/anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/linux-64
https://repo.anaconda.com/pkgs/pro/noarch
package cache : /home/wunan/anaconda3/pkgs
/home/wunan/.conda/pkgs
envs directories : /home/wunan/anaconda3/envs
/home/wunan/.conda/envs
platform : linux-64
user-agent : conda/4.5.11 requests/2.18.4 CPython/3.5.5 Linux/4.15.0-55-generic ubuntu/16.04 glibc/2.23
UID:GID : 1000:1000
netrc file : None
offline mode : False
可以看到版本为4.5.11,python版本3.5.5,是从4.2.0更新的。解决方法为:
$ sudo gedit ~/.bashrc
将 export PATH="/opt/conda/bin:$PATH"(opt/conda is the location where you installed miniconda or Anaconda. It may also be something like ~/Anaconda3 or ~/miniconda2)替换成如下语句
source ~/anaconda3/etc/profile.d/conda.sh
完美解决!