【问题标题】:How to avoid conda activate base from automatically executing in my VS Code editor?如何避免 conda activate base 在我的 VS Code 编辑器中自动执行?
【发布时间】:2020-07-12 01:50:59
【问题描述】:
PS E:\Python and Data Science\PythonDatabase> 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

PS E:\Python and Data Science\PythonDatabase> & C:/Users/Lenovo/Anaconda3/python.exe "e:/Python and Data Science/PythonDatabase/CourseHelper.py"
Hello World
PS E:\Python and Data Science\PythonDatabase> 

【问题讨论】:

    标签: python python-3.x visual-studio-code conda vscode-settings


    【解决方案1】:

    您可以在设置中将"python.terminal.activateEnvironment": false 设置为deactivate activation of your environment。或者,您可以将"python.condaPath" 设置为where conda exists,以便扩展可以适当地使用 conda。

    【讨论】:

      【解决方案2】:

      以@Brett Cannon 的回答为基础...

      您有 2 个选项。除非另有说明,否则以下所有内容均假设您正在更改 VSCode 设置 (F1 -> Terminal:Configure Terminal Settings)。

      选项 1

      使用命令提示符而不是 PowerShell。

      1. 将您的 VSCode 终端切换到命令提示符
      2. settings.json 文件中,将"python.condaPath" 设置为您的conda.exe。例如
      "python.condaPath": "C:\\Users\\<user id>\\Anaconda3\\Scripts\\conda.exe"
      

      选项 2

      设置PATH 变量。

      1. 将 conda.exe 的路径添加到您的 PATH 环境变量中(根据 https://stackoverflow.com/a/66259191/11262633):
          "terminal.integrated.env.windows": {
                  "PATH": "${env:PATH};C:\\Users\\<user id>\\Anaconda3\\Scripts"
          }
      
      1. 启动 PowerShell 终端。您将收到一条消息,指出 Conda 尚未初始化。运行以下命令:
      conda init
      

      请注意,在撰写此答案时,conda init --help 声明此命令是实验性的。

      MicroSoft states 表示 VSCode 目前不支持使用 PowerShell 自动激活 Conda 环境。但是,选项 2 似乎有效。

      【讨论】:

        猜你喜欢
        • 2023-02-08
        • 2019-11-13
        • 1970-01-01
        • 1970-01-01
        • 2019-04-16
        • 1970-01-01
        • 2019-07-18
        • 2016-07-05
        • 1970-01-01
        相关资源
        最近更新 更多