windows下无法用cmd激活conda虚拟环境的问题
问题描述
在cmd运行
conda activate xxx(env_name)
出现如下问题
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'.
但是运行其他conda语句的时候是正常的
打开anaconda powershell prompt 发现存在以下报错
Invoke-Expression : 所在位置 行:1 字符: 1164
+ ... \Xshell 7;C:\Program Files (x86)\NetSarang\Xftp 7;"C:\Program Files\J ...
+ ~~~~~~~~~~
表达式或语句中包含意外的标记“C:\Program”。
所在位置 D:\Programe\Anaconda\shell\condabin\Conda.psm1:109 字符: 15
+ Invoke-Expression -Command $activateCommand;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
问题一
关于anaconda powershell prompt出现的问题可能是环境变量配置出现了错误,由于我的java环境配置出现了重复,对于重复的环境变量删除即可。解决方法见https://blog.csdn.net/weixin_54130714/article/details/125830009.
问题二
解决anaconda powershell一打开就报错的问题后,仍然无法激活conda环境,查阅资料后很多资料都说运行
conda init powershell
(此处如果初次运行conda init 应该会有modified, 我是再次运行init,因此没有change),运行后anaconda powershell可以正常使用
问题三
anaconda powershell可以正常激活conda环境, 但是cmd(或者windows powershell )依然无法激活,因为在windows cmd中激活conda环境不是使用conda activate 命令, 直接使用
activate env_name
在pycharm中激活conda
解决上述问题之后,如果在pycharm的terminal中激活conda环境,也是使用
conda activate env_name