LoginSignup
35
31

More than 5 years have passed since last update.

conda activate の CommandNotFoundError への対処方法

Last updated at Posted at 2018-11-15

初回の conda activate でエラーが出る

conda activate base

のようにして Python 仮想環境を切り替えようとすると、初回実行ではおそらく以下のようなエラーが発生する。

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 ". /Users/iris/miniconda3/etc/profile.d/conda.sh" >> ~/.bash_profile

or, for all users, enable conda with

    $ sudo ln -s /Users/iris/miniconda3/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="/Users/iris/miniconda3/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^

どうすればエラーが解消されるかは書いてあるが、具体的にどうすれば良いのかを次で紹介する。

解決方法

.bashrc.zshrc などに以下を追記すれば良い。リンクを貼る方法も書かれているが、基本的にはこれで大丈夫。

. ${HOME}/miniconda3/etc/profile.d/conda.sh
conda activate base

追記したら source ~/.bashrcexec $SHELL もしくはターミナルを立ち上げなおすなどして設定をロードすることを忘れずに。

source ではなく conda を使う

ちなみに Anaconda や Miniconda で Python 仮想環境を切り替える時は

source activate base

のように source コマンドを使うのをよく見かけると思うが、 conda 4.4.0 (2017-12-20) からは

conda activate base

のように、 source コマンドよりも conda コマンドによる Python 仮想環境の切り替えが推奨されている。

conda activate による Python 仮想環境の切り替えを簡単にする方法についても書いています。

35
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
31