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。