Python终端中激活环境报错IMPORTANT: You may need to close and restart your shell after running ‘conda init‘.

Python运行conda环境报错You may need to close and restart your shell after running ‘conda init’

第一次在Python用conda环境运行代码,点击运行后报错IMPORTANT: You may need to close and restart your shell after running ‘conda init’.

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.
 
To initialize your shell, run
 
    $ conda init <SHELL_NAME>
 
Currently supported shells are:
  - bash
  - cmd.exe
  - 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'.
 

##初步判断是安全问题,在网页找到了一个有效的方法。先以管理员方式打开cmd控制台输入下面两条命令

Get-ExecutionPolicy   #以下命令来查看当前的执行策略
Set-ExecutionPolicy RemoteSigned   #设置执行策略

‘Set-ExecutionPolicy’ 命令将执行策略设置为 ‘RemoteSigned’,这将允许运行由信任的发布者签名的脚本,以及在本地创建的脚本

再次运行代码就正常了

总结:这个报错是因为在你的系统上,PowerShell 的执行策略不允许运行脚本。在 PowerShell 中,执行策略是由 Microsoft 提供的安全机制,用于控制你可以如何执行脚本。执行策略更改为 RemoteSigned,这意味着任何从互联网下载的脚本都需要被签名,但是你本地创建的脚本可以被正常执行。

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值