【问题标题】:Conda activate has no effect康达激活没有效果
【发布时间】:2019-08-02 20:18:51
【问题描述】:

试图在我朋友的 PC 上安装 anaconda 并遇到了这个问题[我修复了它,但找不到答案,所以我想在这里发布] PC只是不会加载anaconda环境, 当你输入

>>conda activate base
>>conda info

 active environment : None

python 可以工作,但是有这个警告

>> python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>>

【问题讨论】:

    标签: python windows powershell


    【解决方案1】:

    这听起来就像your own answer 对自定义代码所做的那样 - 将 Conda 激活码添加到 PowerShell 的配置文件(初始化文件)$PROFILE - 已经与 condainit 预打包命令:

    conda init powershell
    

    查看the docs 或运行conda init --help

    但是请注意,当以这种方式全局初始化 Conda 时,似乎有an issue 激活了另一个基本环境。

    2019 年 3 月链接问题中的评论指出:

    与此同时,您应该能够conda install powershell_shortcut 使用不需要conda init 的替代方式。它没有经过太多测试,因此欢迎并感谢您提供任何反馈。

    【讨论】:

      【解决方案2】:

      那么如何解决:

      首先我们需要在 powershell 中启用脚本,以便我们运行它。

      PS> Set-ExecutionPolicy Unrestricted -Force
      

      这个答案在互联网上的任何地方,但就我而言,它并没有解决问题。 在我的情况下,powershell 没有配置文件,并且没有加载必要的东西。

      所以我们需要通过在 powershell 中输入来创建配置文件:

      PS> New-Item –Path $Profile –Type File –Force
      

      这将创建一个新的配置文件。

      喜欢 profile.ps1

      在\Documents\WindowsPowerShell\中

      然后我们将以下代码添加到文件中

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

      就是这样,下次打开 PowerShell 会话时,您会收到此消息,

      Loading personal and system profiles took 1453ms.
      

      环境应该可以正常工作。

      【讨论】:

      • 这不是conda init powershell 所做的自动吗?
      • 嗯,也许,但我没有看到任何地方,asnwer :D 所以谢谢你现在让我知道!
      • 嗯,也许吧,但我没有找到关于 conda init powershell 的任何信息,奇怪的是我是这样找到的 XD
      【解决方案3】:

      您是否尝试过conda activate base 而不仅仅是activate base

      在我的系统上get-command activate 显示activate 拾取activate.bat,这是不支持powershell 的。 conda 绑定到由 conda ps 模块创建的 powershell 函数。

      似乎 powershell 钩子在路径中添加了太多内容,但我不清楚预期的设置是什么。

      编辑

      刚刚将以下内容添加到我的profile.ps1 以使activate/deactivate 正常工作。唯一的缺点是您无法通过这种方式完成制表符。

      function anaconda_activate([string]$environment) {invoke-conda activate $environment}
      New-Alias -Force activate anaconda_activate
      
      function anaconda_deactivate {invoke-conda deactivate}
      New-Alias -Force deactivate anaconda_deactivate
      

      【讨论】:

        猜你喜欢
        • 2018-04-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-04
        • 2021-11-10
        • 2023-02-13
        • 2016-03-02
        相关资源
        最近更新 更多