【问题标题】:How to set several paths in VScodes Python extension如何在 VScode Python 扩展中设置多个路径
【发布时间】:2021-11-02 12:21:39
【问题描述】:

我想在 VScode(Windows) 中为 Python 扩展设置 2 个解释器路径。 我不知道如何也不想使用 .env 文件。我想添加 Python 2.7 和 3.8

VScode 设置.json:

...    
"python.languageServer": "Pylance",
"python.defaultInterpreterPath": "C:\\Users\\{myuser}\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe",
"python.showStartPage": false,
...

launch.json:

{
     "version": "0.2.0",
     "configurations": [
         {
             "name": "Python: Aktuelle Datei",
             "type": "python",
             "request": "launch",
             "program": "${file}",
             "console": "integratedTerminal",
         }
     ]
 }

我知道有“python.autoComplete.extraPaths”但它不起作用。

【问题讨论】:

  • Python 2.x 已经报废了,再用也没有意义了。 Microsoft Python 扩展还旨在一次支持单个 Python 解释器。

标签: python visual-studio-code vscode-settings vscode-extensions


【解决方案1】:

python 扩展可以自动检测 python 解释器。它将自动在以下位置寻找口译员:

 1. Standard install paths such as /usr/local/bin, /usr/sbin, /sbin, c:\\python27, c:\\python36, etc.
 2. Virtual environments located directly under the workspace (project) folder.
 3. Virtual environments located in the folder identified by the python.venvPath setting (see General settings), which can contain multiple virtual environments. The extension looks for virtual 

等等...您可以参考official docs了解更多信息。

如果 Visual Studio Code 没有自动定位,您也可以manually specify an interpreter 像这样:

【讨论】:

    猜你喜欢
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 2021-09-10
    • 2016-06-14
    • 1970-01-01
    相关资源
    最近更新 更多