首页 > 解决方案 > conda init powershell没有效果

问题描述

我在我的 Windows 笔记本电脑上安装了 Anaconda3 并尝试在 powershell 中使用 conda activate 命令,以便我可以在 VS Code 中将 conda env 用于 Jupyter Notebook。但问题是这样的:

  1. 将 Conda 添加到 Environment-PATH
  2. 我在 conda 提示符下执行了conda init powershell并在战后关闭了它
  3. 打开 powershell 并执行set-executionpolicy remotesigned
  4. 然后我重新启动了电脑
  5. 尽管此时它应该可以工作,但在 powershell中执行conda activate base时我仍然收到以下消息:

CommandNotFoundError:您的 shell 未正确配置为使用“conda activate”。如果使用批处理脚本中的“conda activate”,请将您的调用更改为“CALL conda.bat activate”。要初始化你的 shell,运行 conda init <SHELL_NAME> 当前支持的 shell 是:

  • 重击
  • 命令文件
  • tcsh
  • 呸呸呸
  • zsh
  • 电源外壳

有关更多信息和选项,请参阅“conda init --help”。重要提示:您可能需要在运行“conda init”后关闭并重新启动 shell。

标签: pythonpowershellanacondaconda

解决方案


我注意到您的 powershell 可以conda init成功执行。

2.我在conda提示符下执行了conda init powershell,然后关闭了

通常,此命令将编辑此帐户的 powershell 启动配置文件,该文件位于C:\Users\[YOUR_ACCOUNT_NAME]\Documents\WindowsPowerShell\profile.ps1. 请确保编辑后的文件在您的个人文件夹中包含如下代码:

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

有时,当您的帐户名包含非ASCII字符时,powershell正在使用的代码页可能会导致乱码,从而导致在profile.ps1乱码路径中进行编辑。只需将其复制到您的真实帐户路径中,如上所示。


推荐阅读