win10下安裝anaconda後,使用conda activate命令切換環境出現報錯
C:\Windows\system32> conda activate test
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'.
方法一:
使用anaconda自帶的anaconda navigator或anaconda powershell prompt,anaconda prompt來進入環境,或輸入
conda.bat activate “環境路徑”,例如:conda.bat activate "D:\Anaconda3\envs\test"
方法二:
打開管理員power shell,修改執行策略,執行:get-ExecutionPolicy,回覆Restricted,表示狀態是禁止的
Restricted——默認的設置, 不允許任何script運行
AllSigned——只能運行經過數字證書籤名的script
RemoteSigned——運行本地的script不需要數字簽名,但是運行從網絡上下載的script就必須要有數字簽名
Unrestricted——允許所有的script運行
執行:set-ExecutionPolicy RemoteSigned即可
輸入:conda init,C:\Users\xxx\Documents\WindowsPowerShell下會生成配置文件profile.ps1,重啓power shell後,默認會進入conda的base環境,要恢復刪除profile.ps1。最後根據個人情況,執行set-ExecutionPolicy Restricted策略改回Restricted。