windows安装anaconda3,powershell不能使用命令:conda activate base

问题背景

新电脑到手,需要重新安装环境。
平时以anaconda+vscode为主,因此需要一个方便的入口来访问anaconda和python的和环境,例如vscode下面的终端就是默认使用powershell,如果能在这里访问anaconda是非常方便的。
可惜安装完anaconda后,powershell并不能直接使用conda命令。

问题描述

windows 安装 anaconda3,添加系统环境变量后,powershell不能使用命令:conda activate base

使用该命令会报错:

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

原因分析:

按照网上的方法,首先尝试用管理员身份运行powershell,然后运行:

get-ExecutionPolicy   # 查看系统执行策略状态 
set-executionpolicy remotesigned # 修改执行策略状态

没有效果。


解决方案:

在运行conda init powershell时,发现会在产生一个‘C:\Users\10921\OneDrive\�ĵ�\WindowsPowerShell\profile.ps1’文件,该文件的内容为

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "D:\Programming\Anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

猜测这是powershell的配置文件,但是不在合适的位置。
百度搜索Powershell的配置文件,发现该文件的可能的正确位置是$PROFILE.AllUsersAllHosts
我们把生成的profile.ps1文件放到这个位置(需要管理员权限),再运行conda activate base

加载个人及系统配置文件用了 1579 毫秒。
(base) PS C:\Users\10921\OneDrive\桌面> conda activate base
(base) PS C:\Users\10921\OneDrive\桌面> 

成功!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值