Name already in use
vscode-docs / docs / python / environments.md
- Go to file T
- Go to line L
- Copy path
- Copy permalink
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
Using Python environments in VS Code
This article discusses the helpful Python environments features available in Visual Studio Code. An «environment» in Python is the context in which a Python program runs and consists of an interpreter and any number of installed packages.
Note : If you’d like to become more familiar with the Python programming language, review More Python resources.
By default, any Python interpreter installed runs in its own global environment. For example, if you just run python , python3 , or py at a new terminal (depending on how you installed Python), you’re running in that interpreter’s global environment. Any packages that you install or uninstall affect the global environment and all programs that you run within it.
Do note that if you install packages into your global environment, though, in time it will become crowded with potentially unrelated or unexpected packages and make it difficult to properly test an application. You typically want to create an environment for each workspace.
There are two types of environments that you can create for your workspace: virtual and conda environments. Both types of environment allow you to install packages without affecting other environments. This lets you isolate what packages you install for your workspace so that they don’t interfere with your needs in another workspace.
A virtual environment is a built-in way to create an environment to isolate the packages you install per workspace. A virtual environment creates a folder that contains a copy (or symlink) to a specific interpreter. When you install packages into a virtual environment it will end up in this new folder so that they are not interspersed with other packages used or needed by other workspaces.
Note : While it’s possible to open a virtual environment folder as a workspace, doing so is not recommended and might cause issues with using the Python extension.
A conda environment is a Python environment that’s managed using the conda package manager (see Getting started with conda). Whether to use a conda environment or a virtual one will depend on your packaging needs, what your team has standardized on, etc.
Python environment tools
The following table lists the various tools involved with Python environments:
| Tool | Definition and Purpose |
|---|---|
| pip | The Python package manager that installs and updates packages. It’s installed with Python 3.9+ by default (unless you are on a Debian-based OS; install python3-pip in that case). |
| venv | Allows you to manage separate package installations for different projects and is installed with Python 3 by default (unless you are on a Debian-based OS; install python3-venv in that case) |
| conda | Installed with Miniconda. It can be used to manage both packages and virtual environments. Generally used for data science projects. |
How the extension looks for environments
If an interpreter hasn’t been specified, then the Python extension automatically selects the interpreter with the highest version in the following priority order:
- Virtual environments located directly under the workspace folder.
- Virtual environments related to the workspace but stored globally. For example, Pipenv or Poetry environments that are located outside of the workspace folder.
- Globally installed interpreters. For example, the ones found in /usr/local/bin , C:\\python38 , etc.
Note : The interpreter selected may differ from what python refers to in your terminal.
If Visual Studio Code doesn’t locate your interpreter automatically, you can manually specify an interpreter.
Where the extension looks for environments
The extension automatically looks for interpreters in the following locations, in no particular order:
- Standard install paths such as /usr/local/bin , /usr/sbin , /sbin , c:\\python36 , etc.
- Virtual environments located directly under the workspace (project) folder.
- Virtual environments located in the folder identified by the python.venvPath setting (see General Python settings), which can contain multiple virtual environments. The extension looks for virtual environments in the first-level subfolders of venvPath .
- Virtual environments located in a
Using the Create Environment command
From within VS Code, you can create local environments, using virtual environments or Anaconda, by opening the Command Palette ( kb(workbench.action.showCommands) ), start typing the Python: Create Environment command to search, and then select the command.
The command presents a list of environment types: Venv or Conda.

If you are creating an environment using Venv, the command presents a list of interpreters that can be used as a base for the new virtual environment.

If you are creating an environment using Conda, the command presents a list of Python versions that can be used for your project.

After selecting the desired interpreter or Python version, a notification will show the progress of the environment creation and the environment folder will appear in your workspace.

Note : The command will also install necessary packages outlined in a requirements/dependencies file, such as requirements.txt , pyproject.toml , or environment.yml , located in the project folder. It will also add a .gitignore file to the virtual environment to help prevent you from accidentally committing the virtual environment to source control.
Create a virtual environment in the terminal
If you choose to create a virtual environment manually, use the following command (where «.venv» is the name of the environment folder):
Note : To learn more about the venv module, read Creation of virtual environments on Python.org.
When you create a new virtual environment, a prompt will be displayed in VS Code to allow you to select it for the workspace.

Tip: Make sure to update your source control settings to prevent accidentally committing your virtual environment (in for example .gitignore ). Since virtual environments are not portable, it typically does not make sense to commit them for others to use.
Create a conda environment in the terminal
The Python extension automatically detects existing conda environments. We recommend you install a Python interpreter into your conda environment, otherwise one will be installed for you after you select the environment. For example, the following command creates a conda environment named env-01 with a Python 3.9 interpreter and several libraries:
Note : For more information on the conda command line, you can read Conda environments.
- If you create a new conda environment while VS Code is running, use the refresh icon on the top right of the Python: Select Interpreter window; otherwise you may not find the environment there.

To ensure the environment is set up well from a shell perspective, one option is to use an Anaconda prompt with the activated environment to launch VS Code using the code . command. At that point you just need to select the interpreter using the Command Palette or by clicking on the status bar.
Although the Python extension for VS Code doesn’t currently have direct integration with conda environment.yml files, VS Code itself is a great YAML editor.
Conda environments can’t be automatically activated in the VS Code Integrated Terminal if the default shell is set to PowerShell. To change the shell, see Integrated terminal — Terminal profiles.
You can manually specify the path to the conda executable to use for activation (version 4.4+). To do so, open the Command Palette ( kb(workbench.action.showCommands) ) and run Preferences: Open User Settings. Then set python.condaPath , which is in the Python extension section of User Settings, with the appropriate path.
Working with Python interpreters
Select and activate an environment
As mentioned earlier, the Python extension tries to find and then select what it deems the best environment for the workspace. If you would prefer to select a specific environment, use the Python: Select Interpreter command from the Command Palette ( kb(workbench.action.showCommands) ).

Note : If the Python extension doesn’t find an interpreter, it issues a warning. On macOS 12.2 and older, the extension also issues a warning if you’re using the OS-installed Python interpreter as it is known to have compatibility issues. In either case, you can disable these warnings by setting python.disableInstallationCheck to true in your user settings.
The Python: Select Interpreter command displays a list of available global environments, conda environments, and virtual environments. (See the Where the extension looks for environments section for details, including the distinctions between these types of environments.) The following image, for example, shows several Anaconda and CPython installations along with a conda environment and a virtual environment ( env ) that’s located within the workspace folder:

Note: On Windows, it can take a little time for VS Code to detect available conda environments. During that process, you may see «(cached)» before the path to an environment. The label indicates that VS Code is presently working with cached information for that environment.
If you have a folder or a workspace open in VS Code and you select an interpreter from the list, the Python extension will store that information internally so that the same interpreter will be used once you reopen the workspace.
The Python extension uses the selected environment for running Python code (using the Python: Run Python File in Terminal command), providing language services (auto-complete, syntax checking, linting, formatting, etc.) when you have a .py file open in the editor, and opening a terminal with the Terminal: Create New Terminal command. In the latter case, VS Code automatically activated the selected environment.
Tip: To prevent automatic activation of a selected environment, add «python.terminal.activateEnvironment»: false to your settings.json file (it can be placed anywhere as a sibling to the existing settings).
Tip: If the activate command generates the message «Activate.ps1 is not digitally signed. You cannot run this script on the current system.», then you need to temporarily change the PowerShell execution policy to allow scripts to run (see About Execution Policies in the PowerShell documentation): Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
Note : By default, VS Code uses the interpreter selected for your workspace when debugging code. You can override this behavior by specifying a different path in the python property of a debug configuration. See Choose a debugging environment.
The selected interpreter version will show on the right side of the Status Bar.

The Status Bar also reflects when no interpreter is selected.

In either case, clicking this area of the Status Bar is a convenient shortcut for the Python: Select Interpreter command.
Tip: If you have any problems with VS Code recognizing a virtual environment, please file an issue so we can help determine the cause.
Manually specify an interpreter
If VS Code doesn’t automatically locate an interpreter you want to use, you can browse for the interpreter on your file system or provide the path to it manually.
You can do so by running the Python: Select Interpreter command and select the Enter interpreter path. option that shows on the top of the interpreters list:

You can then either enter the full path of the Python interpreter directly in the text box (for example, «.venv/Scripts/python.exe»), or you can select the Find. button and browse your file system to find the python executable you wish to select.

If you want to manually specify a default interpreter that will be used when you first open your workspace, you can create or modify an entry for the python.defaultInterpreterPath setting.
Note : Changes to the python.defaultInterpreterPath setting are not picked up after an interpreter has already been selected for a workspace; any changes to the setting will be ignored once an initial interpreter is selected for the workspace.
Additionally, if you’d like to set up a default interpreter to all of your Python applications, you can add an entry for python.defaultInterpreterPath manually inside your User Settings. To do so, open the Command Palette ( kb(workbench.action.showCommands) ) and enter Preferences: Open User Settings. Then set python.defaultInterpreterPath , which is in the Python extension section of User Settings, with the appropriate interpreter.
Environments and Terminal windows
After using Python: Select Interpreter, that interpreter is applied when right-clicking a file and selecting Python: Run Python File in Terminal. The environment is also activated automatically when you use the Terminal: Create New Terminal command unless you change the python.terminal.activateEnvironment setting to false .
Please note that launching VS Code from a shell in which a specific Python environment is activated doesn’t automatically activate that environment in the default Integrated Terminal.
Note: conda environments cannot be automatically activated in the integrated terminal if PowerShell is set as the integrated shell. See Integrated terminal — Terminal profiles for how to change the shell.
Changing interpreters with the Python: Select Interpreter command doesn’t affect terminal panels that are already open. You can thus activate separate environments in a split terminal: select the first interpreter, create a terminal for it, select a different interpreter, then use the split button ( kb(workbench.action.terminal.split) ) in the terminal title bar.
Choose a debugging environment
By default, the debugger will use the Python interpreter you’ve selected with the Python extension. However, if you have a python property in the debug configuration of launch.json , that interpreter is used instead. To be more specific, VS Code will give precedence to the python property of the selected debug configuration in launch.json . If it’s not defined, then it will use the path to the Python interpreter you’ve selected for your workspace.
For more details on debug configuration, see Debugging configurations.
Environment variable definitions file
An environment variable definitions file is a simple text file containing key-value pairs in the form of environment_variable=value , with # used for comments. Multiline values aren’t supported, but values can refer to any other environment variable that’s already defined in the system or earlier in the file. Environment variable definitions files can be used for scenarios such as debugging and tool execution (including linters, formatters, IntelliSense, and testing tools), but aren’t applied to the terminal.
Note : Environment variable definitions files are not necessarily cross-platform. For instance, while Unix uses : as a path separator in environment variables, Windows uses ; . There is no normalization of such operating system differences, and so you need to make sure any environment definitions file use values that are compatible with your operating system.
By default, the Python extension looks for and loads a file named .env in the current workspace folder, then applies those definitions. The file is identified by the default entry «python.envFile»: «$
Note : Environment variable definitions files are not used in all situations where environment variables are available for use. Unless Visual Studio Code documentation states otherwise, these only affect certain scenarios as per their definition. For example, the extension doesn’t use environment variable definitions files when resolving setting values.
A debug configuration also contains an envFile property that also defaults to the .env file in the current workspace (see Debugging — Set configuration options). This property allows you to easily set variables for debugging purposes that replace variables specified in the default .env file.
For example, when developing a web application, you might want to easily switch between development and production servers. Instead of coding the different URLs and other settings into your application directly, you could use separate definitions files for each. For example:
dev.env file
prod.env file
You can then set the python.envFile setting to $
Note : When environment variables are specified using multiple methods, be aware that there is an order of precedence. All env variables defined in the launch.json file will override variables contained in the .env file, specified by the python.envFile setting (user or workspace). Similarly, env variables defined in the launch.json file will override the environment variables defined in the envFile that are specified in launch.json .
Use of the PYTHONPATH variable
The PYTHONPATH environment variable specifies additional locations where the Python interpreter should look for modules. In VS Code, PYTHONPATH can be set through the terminal settings ( terminal.integrated.env.* ) and/or within an .env file.
When the terminal settings are used, PYTHONPATH affects any tools that are run within the terminal by a user, as well as any action the extension performs for a user that is routed through the terminal such as debugging. However, in this case when the extension is performing an action that isn’t routed through the terminal, such as the use of a linter or formatter, then this setting won’t have an effect on module look-up.
Setting up Environments ¶
The main purpose of using environments is to create a segregation between the dependencies of different python projects. It eliminates (at least tries to) dependency conflicts since each project has it’s own set of dependencies, isolated from one another.
Suppose you are working on two projects, Project_1 and Project_2 , both of which have a dependency on the same library, let’s say the awesome Requests library. Dependency conflict will arise, if for some reason, the two projects need different versions of Request library. For example, maybe Project_1 needs v1.0.0 , while Project_2 requires the newer v2.0.0 .
This can easily be avoided by using individual environment for each project where all the dependencies of the corresponding project will reside. There are multiple ways you can create environment. We’ll mainly focus on creating python3 based conda environment and native virtual environment .
Conda Environment¶
Installing Anaconda Distribution¶
Install anaconda on your machine. I personally prefer miniconda over the full fledged anaconda. The installation guide can be found here:
Creating Conda Environment¶
After installing anaconda, to create a python3 environment with a specific version of python, type the following command. This will create an environemnt named myenv with python 3.7:
Activating Conda Environment¶
After creating the conda environment, type the folling command to activate the myenv environment:
How can I set up a virtual environment for Python in Visual Studio Code?
In my project folder I created a venv folder:
When I run command select python interpreter in Visual Studio Code, my venv folder is not shown. I went one level up like suggested here, but Visual Studio Code doesn’t see my virtual interpreter.
What did I miss?
![]()
![]()
24 Answers 24
I have been using Visual Studio Code for a while now and found an another way to show virtual environments in Visual Studio Code.
Go to the parent folder in which venv is there through a command prompt.
Type code . and Enter . [It is working on both Windows and Linux for me.]
That should also show the virtual environments present in that folder.
Original Answer
I almost run into same problem every time I am working on Visual Studio Code using venv. I follow the below steps:
Go to menu File → Preferences → Settings.
Click on Workspace settings.
Under Files:Association, in the JSON: Schemas section, you will find Edit in settings.json. Click on that.
Update "python.defaultInterpreterPath": "Your_venv_path/bin/python" under workspace settings. (For Windows): Update "python.defaultInterpreterPath": "Your_venv_path\Scripts\python.exe" under workspace settings.
Restart Visual Studio Code in case if it still doesn’t show your venv.
Note: Use python.pythonPath instead of python.defaultInterpreterPath for older versions.
With a newer Visual Studio Code version it’s quite simple.
Open Visual Studio Code in your project’s folder.
Then open Python Terminal ( Ctrl + Shift + P : Python: Create Terminal)
In the terminal:
You’ll then see the following dialog:

Click Yes ; and your venv is ready to go.
Open a new terminal within VSCode Ctrl + Shift + P and you’ll see that venv is getting picked up; e.g.: (venv) .
You can now instal packages as usual, e.g., pip install sklearn
To keep track of what is installed: pip freeze > requirements.txt
For the older versions of VSCode you may also need to do the following:
Then Python: Select Interpreter (via Ctrl + Shift + P )
And select the option (in my case towards the bottom)
Python 3.7 (venv) ./venv/Scripts/python.exe
Activate.ps1 is not digitally signed. You cannot run this script on the current system.
Installing Modules
Ctrl + Shift + P and Terminal: Create New Integrated Terminal
from the terminal
You can now instal packages as usual, e.g., pip install sklearn .
If you already have your virtualenvs , you only need to open VSCode preferences (Ctrl + ,) and search for venv . Then add the path of the virtualenvs to the “Venv Path” settings, like so:

![]()
I fixed the issue without changing the Python path as that did not seem like the right solution for me. The following solution worked for me, and hopefully it works for you as well :))
Open cmd in Windows / shell in Linux/Mac.
Activate your virtualenv (using source activate / activate.bat / activate.ps1 if using PowerShell)
C:\Users\<myUserName>\Videos\myFolder>django-project\Scripts\activate.bat (django-project) C:\Users\<myUserName>\Videos\myFolder>
Navigate to your project directory and open Visual Studio Code there.
in Visual Studio Code, go to menu File → Preferences → Settings (don’t worry you don’t need to open the JSON file)
In the setting search bar, search for virtual / venv and hit Enter . You should find the below in the search bar:
Python: Venv Folders Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).
Add an item, and then enter the path of the scripts of your virtuanenv which has the activate file in it. For example, in my system, it is:
Save it and restart Visual Studio Code.
To restart, open cmd again, navigate to your project path and open Visual Studio Code. (Note that your venv should be activated in cmd before you open Visual Studio Code from cmd)
Command to open Visual Studio Code from cmd:

![]()
![]()
I was having the same issue until I worked out that I was trying to make my project directory and the virtual environment one and the same — which isn’t correct.
I have a \Code\Python directory where I store all my Python projects. My Python 3 installation is on my Path.
If I want to create a new Python project (Project1) with its own virtual environment, then I do this:
Then, simply opening the folder (Project1) in Visual Studio Code ensures that the correct virtual environment is used.
![]()
For Anaconda users: Just create a venv using Conda, see here. Afterwards, open Visual Studio Code and left-click on the Visual Studio Code interpreter shown in Visual Studio Code at the bottom left:

Choose a virtual environment that pops up in a dropdown of the settings window, and you are done.
![]()
Steps to create virtual environment:
- go to folder containing project
- python3 -m venv evn_name
- source evn_name/bin/activate
- now you will be able to see (env_name) infront of the each terminal line
Now you can install required libraries in virtual environment
- pip3 install -r requirement.txt
- if needed restart code editor
to stop working in virtual environment type: deactivate
to remove virtual environment type: rm -rf evn_name
This is an addition to Sumit S Chawla’s answer that, though it is correct, is missing the fact that anytime you open a folder in Visual Studio Code, it creates a .vscode folder, but those can be multiple, created any time you eventually open a directory.
The .vscode folder has JSON objects that content properties such "setting.json", in which one declare the interpreter to use at that the ".vscode" level (refer to What is a 'workspace' in Visual Studio Code? for more clarifications).
So potentially you could open Visual Studio Code at another level in the virtual environment. It creates another .vscode folder that assume as Python directory those of the global machine and so having such an error, and has I experienced has nothing to do if the virtual environment is activated or not.
This is indeed what happened to me. I have indeed a DjangoRESTAPI_GEN folder in which I initially opened the IDE and it did recognize the virtual environment Python path. Then a few days after I opened it at the level where Git is, so it did create another .vscode folder, that picked the global Python Interpreter, causing my lint in the virtual environment not been used.
Using Python environments in VS Code
This article discusses the helpful Python environments features available in Visual Studio Code. An "environment" in Python is the context in which a Python program runs and consists of an interpreter and any number of installed packages.
Note: If you’d like to become more familiar with the Python programming language, review More Python resources.
Python environments
Global environments
By default, any Python interpreter installed runs in its own global environment. For example, if you just run python , python3 , or py at a new terminal (depending on how you installed Python), you’re running in that interpreter’s global environment. Any packages that you install or uninstall affect the global environment and all programs that you run within it.
Do note that if you install packages into your global environment, though, in time it will become crowded with potentially unrelated or unexpected packages and make it difficult to properly test an application. You typically want to create an environment for each workspace.
Local environments
There are two types of environments that you can create for your workspace: virtual and conda environments. Both types of environment allow you to install packages without affecting other environments. This lets you isolate what packages you install for your workspace so that they don’t interfere with your needs in another workspace.
Virtual environments
A virtual environment is a built-in way to create an environment to isolate the packages you install per workspace. A virtual environment creates a folder that contains a copy (or symlink) to a specific interpreter. When you install packages into a virtual environment it will end up in this new folder so that they are not interspersed with other packages used or needed by other workspaces.
Note: While it’s possible to open a virtual environment folder as a workspace, doing so is not recommended and might cause issues with using the Python extension.
Conda environments
A conda environment is a Python environment that’s managed using the conda package manager (see Getting started with conda). Whether to use a conda environment or a virtual one will depend on your packaging needs, what your team has standardized on, etc.
Python environment tools
The following table lists the various tools involved with Python environments:
| Tool | Definition and Purpose |
|---|---|
| pip | The Python package manager that installs and updates packages. It’s installed with Python 3.9+ by default (unless you are on a Debian-based OS; install python3-pip in that case). |
| venv | Allows you to manage separate package installations for different projects and is installed with Python 3 by default (unless you are on a Debian-based OS; install python3-venv in that case) |
| conda | Installed with Miniconda. It can be used to manage both packages and virtual environments. Generally used for data science projects. |
How the extension looks for environments
If an interpreter hasn’t been specified, then the Python extension automatically selects the interpreter with the highest version in the following priority order:
- Virtual environments located directly under the workspace folder.
- Virtual environments related to the workspace but stored globally. For example, Pipenv or Poetry environments that are located outside of the workspace folder.
- Globally installed interpreters. For example, the ones found in /usr/local/bin , C:\\python38 , etc.
Note: The interpreter selected may differ from what python refers to in your terminal.
If Visual Studio Code doesn’t locate your interpreter automatically, you can manually specify an interpreter.
Where the extension looks for environments
The extension automatically looks for interpreters in the following locations, in no particular order:
- Standard install paths such as /usr/local/bin , /usr/sbin , /sbin , c:\\python36 , etc.
- Virtual environments located directly under the workspace (project) folder.
- Virtual environments located in the folder identified by the python.venvPath setting (see General Python settings), which can contain multiple virtual environments. The extension looks for virtual environments in the first-level subfolders of venvPath .
- Virtual environments located in a
Creating environments
Using the Create Environment command
From within VS Code, you can create local environments, using virtual environments or Anaconda, by opening the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ), start typing the Python: Create Environment command to search, and then select the command.
The command presents a list of environment types: Venv or Conda.

If you are creating an environment using Venv, the command presents a list of interpreters that can be used as a base for the new virtual environment.

If you are creating an environment using Conda, the command presents a list of Python versions that can be used for your project.

After selecting the desired interpreter or Python version, a notification will show the progress of the environment creation and the environment folder will appear in your workspace.

Note: The command will also install necessary packages outlined in a requirements/dependencies file, such as requirements.txt , pyproject.toml , or environment.yml , located in the project folder. It will also add a .gitignore file to the virtual environment to help prevent you from accidentally committing the virtual environment to source control.
Create a virtual environment in the terminal
If you choose to create a virtual environment manually, use the following command (where ".venv" is the name of the environment folder):
Note: To learn more about the venv module, read Creation of virtual environments on Python.org.
When you create a new virtual environment, a prompt will be displayed in VS Code to allow you to select it for the workspace.

Tip: Make sure to update your source control settings to prevent accidentally committing your virtual environment (in for example .gitignore ). Since virtual environments are not portable, it typically does not make sense to commit them for others to use.
Create a conda environment in the terminal
The Python extension automatically detects existing conda environments. We recommend you install a Python interpreter into your conda environment, otherwise one will be installed for you after you select the environment. For example, the following command creates a conda environment named env-01 with a Python 3.9 interpreter and several libraries:
Note: For more information on the conda command line, you can read Conda environments.
- If you create a new conda environment while VS Code is running, use the refresh icon on the top right of the Python: Select Interpreter window; otherwise you may not find the environment there.

To ensure the environment is set up well from a shell perspective, one option is to use an Anaconda prompt with the activated environment to launch VS Code using the code . command. At that point you just need to select the interpreter using the Command Palette or by clicking on the status bar.
Although the Python extension for VS Code doesn’t currently have direct integration with conda environment.yml files, VS Code itself is a great YAML editor.
Conda environments can’t be automatically activated in the VS Code Integrated Terminal if the default shell is set to PowerShell. To change the shell, see Integrated terminal — Terminal profiles.
You can manually specify the path to the conda executable to use for activation (version 4.4+). To do so, open the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ) and run Preferences: Open User Settings. Then set python.condaPath , which is in the Python extension section of User Settings, with the appropriate path.
Working with Python interpreters
Select and activate an environment
As mentioned earlier, the Python extension tries to find and then select what it deems the best environment for the workspace. If you would prefer to select a specific environment, use the Python: Select Interpreter command from the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ).

Note: If the Python extension doesn’t find an interpreter, it issues a warning. On macOS 12.2 and older, the extension also issues a warning if you’re using the OS-installed Python interpreter as it is known to have compatibility issues. In either case, you can disable these warnings by setting python.disableInstallationCheck to true in your user settings.
The Python: Select Interpreter command displays a list of available global environments, conda environments, and virtual environments. (See the Where the extension looks for environments section for details, including the distinctions between these types of environments.) The following image, for example, shows several Anaconda and CPython installations along with a conda environment and a virtual environment ( env ) that’s located within the workspace folder:

Note: On Windows, it can take a little time for VS Code to detect available conda environments. During that process, you may see "(cached)" before the path to an environment. The label indicates that VS Code is presently working with cached information for that environment.
If you have a folder or a workspace open in VS Code and you select an interpreter from the list, the Python extension will store that information internally so that the same interpreter will be used once you reopen the workspace.
The Python extension uses the selected environment for running Python code (using the Python: Run Python File in Terminal command), providing language services (auto-complete, syntax checking, linting, formatting, etc.) when you have a .py file open in the editor, and opening a terminal with the Terminal: Create New Terminal command. In the latter case, VS Code automatically activated the selected environment.
Tip: To prevent automatic activation of a selected environment, add "python.terminal.activateEnvironment": false to your settings.json file (it can be placed anywhere as a sibling to the existing settings).
Tip: If the activate command generates the message "Activate.ps1 is not digitally signed. You cannot run this script on the current system.", then you need to temporarily change the PowerShell execution policy to allow scripts to run (see About Execution Policies in the PowerShell documentation): Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
Note: By default, VS Code uses the interpreter selected for your workspace when debugging code. You can override this behavior by specifying a different path in the python property of a debug configuration. See Choose a debugging environment.
The selected interpreter version will show on the right side of the Status Bar.

The Status Bar also reflects when no interpreter is selected.

In either case, clicking this area of the Status Bar is a convenient shortcut for the Python: Select Interpreter command.
Tip: If you have any problems with VS Code recognizing a virtual environment, please file an issue so we can help determine the cause.
Manually specify an interpreter
If VS Code doesn’t automatically locate an interpreter you want to use, you can browse for the interpreter on your file system or provide the path to it manually.
You can do so by running the Python: Select Interpreter command and select the Enter interpreter path. option that shows on the top of the interpreters list:

You can then either enter the full path of the Python interpreter directly in the text box (for example, ".venv/Scripts/python.exe"), or you can select the Find. button and browse your file system to find the python executable you wish to select.

If you want to manually specify a default interpreter that will be used when you first open your workspace, you can create or modify an entry for the python.defaultInterpreterPath setting.
Note: Changes to the python.defaultInterpreterPath setting are not picked up after an interpreter has already been selected for a workspace; any changes to the setting will be ignored once an initial interpreter is selected for the workspace.
Additionally, if you’d like to set up a default interpreter to all of your Python applications, you can add an entry for python.defaultInterpreterPath manually inside your User Settings. To do so, open the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ) and enter Preferences: Open User Settings. Then set python.defaultInterpreterPath , which is in the Python extension section of User Settings, with the appropriate interpreter.
Environments and Terminal windows
After using Python: Select Interpreter, that interpreter is applied when right-clicking a file and selecting Python: Run Python File in Terminal. The environment is also activated automatically when you use the Terminal: Create New Terminal command unless you change the python.terminal.activateEnvironment setting to false .
Please note that launching VS Code from a shell in which a specific Python environment is activated doesn’t automatically activate that environment in the default Integrated Terminal.
Note: conda environments cannot be automatically activated in the integrated terminal if PowerShell is set as the integrated shell. See Integrated terminal — Terminal profiles for how to change the shell.
Changing interpreters with the Python: Select Interpreter command doesn’t affect terminal panels that are already open. You can thus activate separate environments in a split terminal: select the first interpreter, create a terminal for it, select a different interpreter, then use the split button ( ⌘\ (Windows, Linux Ctrl+Shift+5 ) ) in the terminal title bar.
Choose a debugging environment
By default, the debugger will use the Python interpreter you’ve selected with the Python extension. However, if you have a python property in the debug configuration of launch.json , that interpreter is used instead. To be more specific, VS Code will give precedence to the python property of the selected debug configuration in launch.json . If it’s not defined, then it will use the path to the Python interpreter you’ve selected for your workspace.
For more details on debug configuration, see Debugging configurations.
Environment variables
Environment variable definitions file
An environment variable definitions file is a simple text file containing key-value pairs in the form of environment_variable=value , with # used for comments. Multiline values aren’t supported, but values can refer to any other environment variable that’s already defined in the system or earlier in the file. Environment variable definitions files can be used for scenarios such as debugging and tool execution (including linters, formatters, IntelliSense, and testing tools), but aren’t applied to the terminal.
Note: Environment variable definitions files are not necessarily cross-platform. For instance, while Unix uses : as a path separator in environment variables, Windows uses ; . There is no normalization of such operating system differences, and so you need to make sure any environment definitions file use values that are compatible with your operating system.
By default, the Python extension looks for and loads a file named .env in the current workspace folder, then applies those definitions. The file is identified by the default entry "python.envFile": "$
Note: Environment variable definitions files are not used in all situations where environment variables are available for use. Unless Visual Studio Code documentation states otherwise, these only affect certain scenarios as per their definition. For example, the extension doesn’t use environment variable definitions files when resolving setting values.
A debug configuration also contains an envFile property that also defaults to the .env file in the current workspace (see Debugging — Set configuration options). This property allows you to easily set variables for debugging purposes that replace variables specified in the default .env file.
For example, when developing a web application, you might want to easily switch between development and production servers. Instead of coding the different URLs and other settings into your application directly, you could use separate definitions files for each. For example:
dev.env file
prod.env file
You can then set the python.envFile setting to $
Note: When environment variables are specified using multiple methods, be aware that there is an order of precedence. All env variables defined in the launch.json file will override variables contained in the .env file, specified by the python.envFile setting (user or workspace). Similarly, env variables defined in the launch.json file will override the environment variables defined in the envFile that are specified in launch.json .
Use of the PYTHONPATH variable
The PYTHONPATH environment variable specifies additional locations where the Python interpreter should look for modules. In VS Code, PYTHONPATH can be set through the terminal settings ( terminal.integrated.env.* ) and/or within an .env file.
When the terminal settings are used, PYTHONPATH affects any tools that are run within the terminal by a user, as well as any action the extension performs for a user that is routed through the terminal such as debugging. However, in this case when the extension is performing an action that isn’t routed through the terminal, such as the use of a linter or formatter, then this setting won’t have an effect on module look-up.