Skip to content

[已解決] CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’. To initialize your shell, run…

問題描述

今天在我使用 Anaconda 啟用 Python 的環境時,我得到了以下錯誤訊息,導致無法進入虛擬環境。

(Anaconda 所啟用的不同虛擬環境之間是獨立的,讓我們可以在不同的環境中開發不同的專案

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


這個錯誤若是出現,你會發現自己根本沒有進入虛擬環境,根本還停留在原生環境。


解決方法

這個問題的出現是因為在上次激活環境時,使用了 conda activate <ENVIRONMENT> 後並未使用 conda deactivate 關閉環境所導致的。

如果使用錯誤訊息中提示的 conda init <SHELL_NAME> 來進行初始化的話,會需要重新啟動終端機。

實際上,我覺得有更快的解決方法:那就是直接使用 source activate 來重新進入之前已經啟用的虛擬環境。

如果該虛擬環境就是你希望啟用的,那就可以直接開始工作了。

如果你發現你進入了一個不是你希望的虛擬環境(這真的有可能發生),那麼你可以會希望使用 conda deactivate 來退出這個環境,接下來你就可以重新使用 conda activate 來啟用任意你想要的環境了。

順帶一提如果你遺忘了有哪些環境你已經建立,你可以透過 conda env list 來確認你的虛擬環境名稱。


References


Read More

Leave a Reply