简体   繁体   English

使用Visual Studio代码将多个virtualenv添加到python解释器

[英]adding multiple virtualenv to python interpreter using visual studio code

I searched literally everywhere and I can't figure out how to add multiple python interpreters with visual studio code. 我到处搜索了字词,却想不出如何在Visual Studio代码中添加多个python解释器。 By the way, I'm quite new to visual studio code. 顺便说一句,我对Visual Studio代码还很陌生。

I'm wondering if there something I need to do in the user settings to add multiple python.PythonPath directories. 我想知道是否需要在用户设置中添加多个python.PythonPath目录。 At the moment I only have 2 interpreter my venv and the default python interpreter 目前我只有2个解释器我的venv和默认的python解释器

    "python.pythonPath": 
 "C:\\Users\\<name>\\Projects\\Test\\Venv\\Scripts\\python.exe",

The setting "python.pythonPath": would normally apply to your workspace settings. 设置"python.pythonPath":通常将应用于您的工作空间设置。 So, if you have multiple projects, vscode will the interpreter for each project automatically. 因此,如果您有多个项目,则vscode将自动为每个项目提供解释器。

To switch once your project is open, open the command palette ( shift + cmd + P or F1 ) and type '>Python: Select Interpreter' to choose between the interpreters available to your project. 要在项目打开后进行切换,请打开命令面板( shift + cmd + PF1 ),然后键入“> Python:Select Interpreter”以在可用于项目的解释器之间进行选择。

If you store your virtual enviornments in a non-defeault location, you can use the settings python.venvFolders and python.venvPath in to tell vscode where to find them. 如果将虚拟环境存储在非防御位置,则可以使用设置python.venvFolderspython.venvPath告诉vscode在哪里找到它们。

If that is not enough, you could create a tasks.json to specify command including the exact paths, ie: 如果这还不够,您可以创建一个tasks.json来指定包含确切路径的命令,即:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run mock",
            "type": "shell",
            "command": "pipenv run ./run.py --mock",
            "problemMatcher": [
                "$eslint-compact"
                ]
         },
    ],
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM