【问题标题】:Conda not activated in Power Shell未在 Powershell 中激活 Conda
【发布时间】:2020-09-16 20:11:00
【问题描述】:

我已经在我的 Windows 10 笔记本电脑上安装了 anaconda。我正在尝试激活名为 pyenv 的 Python 环境。

首先,我检查了笔记本电脑中的conda env list,这是电源外壳上的输出:

PS C:\Users\User> conda env list
# conda environments:
#
base                  *  C:\Users\User\Anaconda3
pyenv                    C:\Users\User\Anaconda3\envs\pyenv

然后我激活pyenv:

PS C:\Users\User> conda activate pyenv

但是我再检查一遍,还是激活base环境:

PS C:\Users\User> conda env list
# conda environments:
#
base                  *  C:\Users\User\Anaconda3
pyenv                    C:\Users\User\Anaconda3\envs\pyenv

当我使用 Anaconda 提示符时,它工作正常:

(base) C:\Users\User>conda activate pyenv

(pyenv) C:\Users\User>

有谁知道为什么会导致这个问题以及如何解决这个问题?

更新:

运行conda init powershell:

PS C:\Users\User> conda init powershell
no change     C:\Users\User\Anaconda3\Scripts\conda.exe
no change     C:\Users\User\Anaconda3\Scripts\conda-script.py
no change     C:\Users\User\Anaconda3\Scripts\conda-env-script.py
no change     C:\Users\User\Anaconda3\condabin\conda.bat
no change     C:\Users\User\Anaconda3\Library\bin\conda.bat
no change     C:\Users\User\Anaconda3\condabin\_conda_activate.bat
no change     C:\Users\User\Anaconda3\condabin\rename_tmp.bat
no change     C:\Users\User\Anaconda3\condabin\conda_hook.bat
no change     C:\Users\User\Anaconda3\Scripts\activate.bat
no change     C:\Users\User\Anaconda3\condabin\activate.bat
no change     C:\Users\User\Anaconda3\condabin\deactivate.bat
modified      C:\Users\User\Anaconda3\etc\profile.d\conda.sh
modified      C:\Users\User\Anaconda3\etc\fish\conf.d\conda.fish
no change     C:\Users\User\Anaconda3\shell\condabin\Conda.psm1
modified      C:\Users\User\Anaconda3\shell\condabin\conda-hook.ps1
no change     C:\Users\User\Anaconda3\Lib\site-packages\xontrib\conda.xsh
modified      C:\Users\User\Anaconda3\etc\profile.d\conda.csh
modified      C:\Users\User\Documents\WindowsPowerShell\profile.ps1

更新 2: 使用 CMD 时有效:

C:\Users\User>conda activate pyenv

(pyenv) C:\Users\User>

【问题讨论】:

  • 当你运行conda activate pyenv时,它会抛出任何错误或警告吗?
  • @Anwarvic 不,它不打印任何东西。
  • 你使用的是什么版本的 conda?
  • @bug_spray conda 版本:4.8.1。 conda-build 版本:3.17.8
  • 您可能需要在conda init powershell 之后关闭并重新打开 Powershell。否则,可能会在 github 上打开一个问题

标签: python powershell anaconda


【解决方案1】:

一段时间后,我的Powershell打开时出现此错误。

. : File C:\Users\User\Documents\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
    + . 'C:\Users\BinoyGhosh\Documents\WindowsPowerShell\profile.ps1'
    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [], PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess

然后我发现了这个solution

  • 以管理员身份运行 Powershell
  • 运行此行set-executionpolicy remotesigned
  • 关闭终端

然后就可以了。

【讨论】:

  • 运行命令后出现的错误统计信息:conda init powershell
  • @AgustinBarrachina 是的,它在我运行该命令后出现。
  • 确保重启终端。然后运行 ​​conda activate...
【解决方案2】:

上述解决方案并不完全适合我。我不得不另外运行:

conda init powershell

重启powershell后就可以运行了:

conda activate myenv

成功了。

【讨论】:

    猜你喜欢
    • 2019-08-30
    • 1970-01-01
    • 2021-01-16
    • 2021-07-18
    • 1970-01-01
    • 2019-01-13
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多