【问题标题】:How to switch to Anaconda environment in VS code without adding Anaconda to system PATH如何在VS代码中切换到Anaconda环境而不将Anaconda添加到系统PATH
【发布时间】:2021-11-10 22:48:45
【问题描述】:

我尝试在 Visual Studio 代码中使用 Anaconda 环境,并选择了 conda 环境作为解释器。 但是当我单击“在终端中运行 Python 文件”时,首先运行“conda activate base”命令。

PS C:path\to\workspace> conda activate base
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,     
verify that the path is correct and try again.
At line:1 char:1
+ conda activate base
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

但是我还没有将Anaconda环境添加到系统PATH,因为官网说它可能会导致问题。

所以我想知道有没有办法在不将 conda 环境添加到系统路径的情况下使用它?我知道我可以使用code path/to/workspace 在 Anaconda Prompt 中启动 vscode。但是我无法切换到 vscode 中的其他解释器。

【问题讨论】:

  • 注意不要使用base环境进行开发,会导致一堆问题。

标签: python visual-studio-code anaconda conda


【解决方案1】:

你能找到这个文件吗?

C:\Users\{UserName}\Documents\WindowsPowerShell\profile.ps1

如果没有,可以尝试用以下命令初始化:

conda init powershell

【讨论】:

    【解决方案2】:

    如果您不打算设置系统 PATH,您可以使用 settings.json 进行 vscode

    {
      "python.defaultInterpreterPath": "C:\Users\<username>\Anaconda3\envs\<env name>\bin\python.exe"
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 2019-06-03
      • 2018-04-03
      • 2021-07-09
      • 2018-11-06
      • 1970-01-01
      • 2020-02-16
      • 2015-12-13
      • 1970-01-01
      相关资源
      最近更新 更多