powershell 进入conda_解决PowerShell无法使用Anaconda的问题

软硬件环境

  • windows 10 64bit
  • python 3.7 with anaconda
  • conda 4.8.3

前言

前面的文章 Anaconda的基本使用 已经介绍过anaconda的基本安装及使用了,但是在windows中,如果终端工具使用的是PowerShell,会发现conda的一些命令无效

640?wx_fmt=png

powershell

当使用conda activate DCenter后,并没有进入到DCenter这个虚拟环境

640?wx_fmt=png

powershell

不过在CMD中,conda的功能是正常的

640?wx_fmt=png

powershell

解决方法

以管理员身份打开PowerShell,执行命令

conda init powershell

640?wx_fmt=png

powershell

完成后关闭PowerShell再重新打开,这时候报错了

640?wx_fmt=png

powershell

这个错误是PowerShell默认禁止脚本运行而导致的,是PowerShell的默认脚本执行策略(execution policy)。通过执行命令

get-executionpolicy

可以查看当前PowerShell的执行策略

640?wx_fmt=png

powershell

默认的执行策略是Restricted,关于这个策略,可以看看下面这张表

640?wx_fmt=png

powershell

接下来就可以修改执行策略了,执行

set-executionpolicy remotesigned

640?wx_fmt=png

powershell

上面的remotesigned是我们要修改的执行策略,关于这个策略可以参考下面这张表

640?wx_fmt=png

powershell

设置了新的策略,我们再通过get-executionpolicy来检查下是否设置成功

最后再次重新打开PowerShell,执行conda activate $虚拟环境

640?wx_fmt=png

powershell

搞定!

参考资料

  • https://github.com/conda/conda/issues/8428
  • https://xugaoxiang.com/2019/12/08/anaconda
  • https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7
  • 19
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值