【问题标题】:How to activate conda environment from powershell?如何从 powershell 激活 conda 环境?
【发布时间】:2021-01-16 20:09:36
【问题描述】:

版本Anaconda 4.8.3

我不能做什么:
我无法从 powershell 激活任何环境。 conda activate base

我能做什么:
conda env list conda create -n xxxconda remove -n xxx

我尝试了很多解决方案,但结果都没有用:

  1. conda init powershell
    restart powershell
    conda activate

  2. conda update -n base conda 并重做 1

  3. conda install -n root -c pscondaenvs pscondaenvs
    Set-ExecutionPolicy RemoteSigned
    activate base

The result of running conda activate

【问题讨论】:

  • 您在尝试 conda init 时是否以提升/管理员权限运行 Powershell?没有错误?
  • 是的,我尝试了管理员和非管理员的 powershell,结果是一样的。 " 没有改变 " @AMC

标签: powershell anaconda windows-10


【解决方案1】:

您不需要管理员权限。

在 Windows 上安装 Anaconda 或 Miniconda 后,从“开始”菜单打开 Anaconda Powershell Prompt

或者,如果你在那里没有看到它,那么假设你已经安装了 路径 C:\miniconda3\4.9.2 处的 miniconda3,执行:

powershell -ExecutionPolicy ByPass -NoExit -Command "& 'C:\miniconda3\4.9.2\shell\condabin\conda-hook.ps1' ; conda activate 'C:\miniconda3\4.9.2' "

现在试试:

conda init powershell

然后重新打开 powershell。

补充说明:默认情况下,当我们打开终端时,conda 会自动激活。如果您不喜欢,请使用以下命令禁用自动激活:

conda config --set auto_activate_base false

【讨论】:

  • 解决方案看起来很有希望,但实际上它并没有绕过限制,并且在重新启动后(通过 conda 完全修改文件)它仍然无法正常工作。重新启动相同的\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:3(引用自动创建的 ps 脚本)
  • 在这种情况下你只需要unblock the file named profile.ps1:Unblock-File -Path .\profile.ps1(将相对路径替换为完整路径)见Unblock-File cmdlet doc
【解决方案2】:

从“开始”菜单打开Anaconda Powershell Prompt。 现在试试:

conda init powershell

现在重启powershell,如果在powershell中发现这样的错误:

\WindowsPowerShell\profile.ps1 无法加载,因为此系统上禁用了运行脚本。有关详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkID=135170 上的 about_Execution_Policies。在 line:1 char:3

然后更改执行策略。将此代码键入到 powershell:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

要了解有关执行政策的更多信息,您可以访问此link

【讨论】:

  • 没有管理员权限:Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
【解决方案3】:

当您在 Anacondaprompt 中使用 Anaconda 或 Miniconda 类型时:

conda init powershell

【讨论】:

    【解决方案4】:

    遇到了同样的问题。诀窍是确保环境包含在 Windows Powershell 的 PATH 变量中。要查看 PATH 变量,请在 powershell 中输入以下内容:

    $env:Path.split(';')
    

    如果您想要的环境没有出现在输出列表中,如 ...... ...... ..../envs/yourEnv/... .....

    在 cmd 上运行以下命令:

    conda init powershell
    

    然后重启_Anaconda Powershell, 那么:

    conda activate yourEnv
    

    希望 conda 提示现在应该显示您想要的环境。

    【讨论】:

      【解决方案5】:

      & 'C:\ProgramData\Miniconda3\shell\condabin\conda-hook.ps1'; conda activate 'C:\ProgramData\Miniconda3'

      这是在我电脑上的Anaconda Powershell Prompt (Miniconda3).lnk 中找到的命令。

      在我的机器上,通过执行这两个命令,我可以在任何地方进入环境。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-08
        • 2018-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-23
        • 1970-01-01
        相关资源
        最近更新 更多