To activate a venv in VSCode, select it with Python: Select Interpreter and open a new terminal, which runs the activation command for you, or run .venv\Scripts\Activate.ps1 on Windows or source .venv/bin/activate on macOS and Linux.
This guide covers creating the environment, activating it in every shell, checking that VS Code really uses it, and fixing the errors that stop activation.

Activating venv in VSCode
Once VS Code knows which environment belongs to the workspace, every new integrated terminal activates it automatically. This is the route that needs no typed commands.
- Open your project folder with File > Open Folder.
- Press Ctrl+Shift+P (Cmd+Shift+P on a Mac) to open the Command Palette.
- Run Python: Select Interpreter and choose the entry for your .venv folder.
- Press Ctrl+Shift+` to open a new terminal.
- Check that the prompt now starts with (.venv), which shows the environment is active.
Terminals that were already open keep their old state, so always open a fresh one after you switch environments.
Importance of activation in VSCode
Activation decides which Python and which packages run when you type a command. VS Code tracks two separate things: the selected interpreter and the terminal's active environment.
| What activation changes | Effect in VS Code |
|---|---|
| PATH order | The environment's Scripts (Windows) or bin (macOS, Linux) folder goes first, so python and pip run from the venv |
| Package installs | python -m pip install puts packages in the venv, isolated from the global Python |
| Terminal prompt | The prompt shows the environment name, such as (.venv) |
| VIRTUAL_ENV variable | Set to the environment's path while it is active |
| Run, debug and IntelliSense | Use the interpreter picked with Python: Select Interpreter, not the terminal's activation |
Activation is not strictly required: Python's documentation notes you can run the environment's interpreter by its full path instead. Activation just saves typing that path.
Prerequisites for activating venv in VSCode
| Requirement | How to check or get it |
|---|---|
| Python 3 interpreter | Run py -3 --version on Windows or python3 --version on macOS and Linux; you can install Python from the command line if it is missing |
| Visual Studio Code | Any current release; get VS Code for Windows or Mac from the official installer |
| Python extension | Open Extensions with Ctrl+Shift+X, search Python and install the Microsoft extension |
| A project folder | Open it with File > Open Folder, or run code . inside it |
| macOS only | VS Code does not support the system Python on macOS; Microsoft recommends a Homebrew install (brew install python3) |
If you install Python while VS Code is open, close and reopen the terminal so it picks up the new PATH.
Step-by-step guide to creating a virtual environment in VSCode
This is the full sequence from an empty folder to a working, activated environment.
- Install Python and VSCode, plus the Python extension from the Extensions view.
- Open your project directory with File > Open Folder.
- Open the integrated terminal with Ctrl+`.
- Create the virtual environment with
python -m venv .venv(Windows) orpython3 -m venv .venv(macOS, Linux). - Activate the virtual environment with
.venv\Scripts\Activate.ps1(PowerShell) orsource .venv/bin/activate(bash, zsh). - Confirm activation: the prompt starts with (.venv) and the Status Bar shows the venv's Python version.
- Use the virtual environment: install packages with
python -m pip install <package>and run your script from the same terminal.
Create a virtual environment
VS Code can build the environment for you, which also selects it for the workspace in one pass.
- Press Ctrl+Shift+P and run Python: Create Environment.
- Select Venv as the environment type.
- Choose the Python interpreter the environment should be based on.
- Pick a requirements.txt or pyproject.toml if VS Code offers to install dependencies.
- Wait for the notification to finish; a .venv folder appears in the Explorer.
- Or open the Python sidebar, expand Environment Managers and select + for Quick Create, which uses the latest Python and names the folder .venv.
If uv is installed, the Python Environments extension uses it automatically for venv creation, controlled by the python-envs.alwaysUseUv setting.

Creating a virtual environment from the VS Code terminal
The command line route works in any shell and gives the same .venv folder.
python -m venv .venv
Runs Python's built-in venv module and creates a folder named .venv in the current directory with its own Python, pip, activation scripts and a pyvenv.cfg file. Use python3 instead of python on macOS and Linux.
You should see: A .venv folder containing Scripts (Windows) or bin (macOS, Linux) appears in the Explorer, and VS Code may ask whether to select it for the workspace.
Activate the virtual environment
Manual activation is a single command typed into the VS Code terminal from the project root.
- Open a terminal with Ctrl+` and make sure it is in the folder that contains .venv.
- Check which shell the terminal uses; its name appears in the terminal tab list on the right.
- Type the activation command for that shell from the table below and press Enter.
- Look for (.venv) at the start of the prompt.
- Run your Python commands in this same terminal; other open terminals are not affected.
Activating venv in different operating systems
The activation script lives in Scripts on Windows and bin on macOS and Linux, and each shell has its own script.
| Operating system | Shell | Activation command |
|---|---|---|
| Windows | PowerShell | .venv\Scripts\Activate.ps1 |
| Windows | Command Prompt (cmd.exe) | .venv\Scripts\activate.bat |
| macOS, Linux | bash or zsh | source .venv/bin/activate |
| macOS, Linux | fish | source .venv/bin/activate.fish |
| macOS, Linux | csh or tcsh | source .venv/bin/activate.csh |
| macOS, Linux | PowerShell (pwsh) | .venv/bin/Activate.ps1 |
How to activate venv in VS Code on Windows
On Windows, PowerShell and Command Prompt each have their own activation script in the Scripts folder.
- Press Ctrl+` to open the terminal in your project folder.
- Type
.venv\Scripts\Activate.ps1and press Enter. - If PowerShell says the script cannot be loaded, open a Command Prompt terminal from the terminal dropdown instead and run
.venv\Scripts\activate.bat. - To keep using PowerShell, run
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser, the setting Python's own documentation gives for Activate.ps1. - Open a new terminal and run the activation command again.
Microsoft lists RemoteSigned as the default policy for Windows computers; it still blocks unsigned scripts downloaded from the internet, and the CurrentUser scope changes nothing for other accounts.

How to activate venv on macOS and Linux
On macOS and Linux, use python3 to create the environment and source the script in bin.
- Open the terminal with Ctrl+` (the shortcut is the same on a Mac).
- Create the environment if needed with
python3 -m venv .venv. - Run
source .venv/bin/activatein bash or zsh. - Use
source .venv/bin/activate.fishin fish, orsource .venv/bin/activate.cshin csh. - Install packages with
python3 -m pip install <package>while (.venv) shows in the prompt.
Configure VSCode to use the virtual environment
Selecting the interpreter is what makes Run, Debug and IntelliSense use the venv, whatever the terminal shows.
- Open any .py file in the project.
- Select the Python version in the Status Bar at the bottom of the window.
- Pick the interpreter listed under your .venv folder.
- Or press Ctrl+Shift+P and run Python: Select Interpreter to choose from the same list.
- Open a new terminal so it activates the selected environment.
Without a manual choice, VS Code picks a workspace-local .venv or venv before any global interpreter. The debugger uses the selected environment unless launch.json sets a different python path.
Configuring VSCode for Python virtual environments
These settings come from the Python Environments extension and control how environments are found and activated.
| Setting | Default | What it controls |
|---|---|---|
| python-envs.terminal.autoActivationType | command | How new terminals activate the venv: command runs it visibly, shellStartup activates through shell startup scripts, off disables it |
| python-envs.workspaceSearchPaths | ./**/.venv | Where VS Code looks for environments in the workspace; set it at workspace level |
| python-envs.globalSearchPaths | empty | Absolute paths for environments outside the workspace, such as a shared envs folder |
| python-envs.defaultEnvManager | ms-python.python:venv | Which manager Quick Create uses: venv or conda |
| python-envs.alwaysUseUv | true | Use uv for venv creation and installs when it is available |
| python.defaultInterpreterPath | not set | Legacy fallback interpreter, still honoured |
Restart your terminals after you change autoActivationType. The old python.terminal.activateEnvironment setting maps to this one, and the new setting wins.

Verifying the activation of venv
Three checks tell you whether the terminal and the editor both use the environment.
- Look at the terminal prompt: (.venv) at the start means the shell activated the environment.
- Look at the Status Bar: the Python version shown should be the one from .venv.
- Run the interpreter check below and confirm it prints True.
- Install or import a package to make sure it lands in the venv, not the global Python.
Check the Python interpreter
Python's documentation gives a reliable test: inside a virtual environment, sys.prefix differs from sys.base_prefix.
python -c "import sys; print(sys.prefix != sys.base_prefix, sys.prefix)"
sys.prefix points to the virtual environment while it is in use, and sys.base_prefix points to the Python installation it was created from.
You should see: The output starts with True followed by the path to your project's .venv folder. False means the terminal is still on the global Python.
Use the integrated terminal
The integrated terminal is where activation actually happens, and VS Code activates it for you once an environment is selected.
- Press Ctrl+Shift+` or select + in the Terminal panel to open a fresh terminal.
- Watch the first lines: with the default command activation type, VS Code types and runs the activation command visibly.
- To open a terminal for a different environment, right-click it in Environment Managers and select Open in Terminal.
- Close stale terminals with the trash can icon on their tab.
- Run scripts with Run Python File in Terminal from the editor's right-click menu so they use the selected interpreter.

Test package availability
Installing and importing a package proves that pip and Python both point at the venv.
python -m pip install numpy
Uses the active interpreter's pip, so the package goes into .venv. Use python3 on macOS and Linux. Then run your script or python -c "import numpy" in the same terminal.
You should see: The import works without ModuleNotFoundError. If the error appears in Run or Debug but not in the terminal, the selected interpreter is not the venv.
You can also install packages without a terminal: right-click the environment in Environment Managers and select Manage Packages.
Integrating venv with VSCode features
Most VS Code features read the selected interpreter, so one choice covers the editor, the debugger and the tests.
| VS Code feature | Uses the venv when | Note |
|---|---|---|
| Run Python File | The venv is the selected interpreter | Opens a terminal with the environment activated |
| Debugging | The venv is selected, or set as python in launch.json | launch.json overrides the selection |
| IntelliSense and Pylance | The venv is selected | Pylance uses one interpreter per workspace folder |
| Test Explorer | Each Python project has an environment | Each project gets its own test tree |
| Jupyter notebooks | You pick the venv as the kernel | Kernel list may differ from Environment Managers |
| Terminal | autoActivationType is not off | Only new terminals activate |
Common issues and troubleshooting when activating venv in VSCode
The environment shows as (broken)
The pyvenv.cfg file is missing or the environment's Python executable is invalid.
- Delete the environment: right-click it in Environment Managers and select Delete.
- Create it again with Python: Create Environment.
- Reinstall packages with
python -m pip install -r requirements.txt.
ModuleNotFoundError after installing a package
The package went into a different interpreter from the one running your code.
- Run Python: Select Interpreter and choose the .venv entry.
- Open a new terminal and run
python -m pip install <package>again. - Rerun the script from that terminal.
The venv stopped working after you moved the project folder
Scripts inside a venv store absolute paths, so environments are not portable.
- Save the package list with
pip freeze > requirements.txtfrom the old environment if it still runs. - Delete the old .venv folder.
- Create a new one in the new location and install from requirements.txt.
Issue: venv not showing up in Command Palette
Python: Select Interpreter does not list your venv
The folder is outside the search paths, or the discovery cache is stale.
- Press Ctrl+Shift+P and run Python Environments: Refresh All Environment Managers.
- If the venv is not named .venv, add its path to python-envs.workspaceSearchPaths in workspace settings.
- For an environment outside the project, add its absolute path to python-envs.globalSearchPaths.
- Run Python: Select Interpreter again.

Issue: Unable to activate venv via terminal
PowerShell refuses to run Activate.ps1
The execution policy for your account does not allow local scripts.
- Switch the terminal to Command Prompt and run
.venv\Scripts\activate.bat. - Or run
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUseronce, as Python's documentation suggests. - Check the result with
Get-ExecutionPolicy -Scope CurrentUser, then open a new terminal.
The activate script is not found
The terminal is not in the project root, or the command uses the wrong folder for your OS.
- Run the command from the folder that contains .venv.
- Use Scripts on Windows and bin on macOS and Linux.
- Use
sourcebefore the script name in bash, zsh, fish and csh.
Issue: VSCode not using the venv interpreter
The Status Bar or Run button still uses the global Python
Another interpreter is selected, or a setting such as python.defaultInterpreterPath overrides discovery.
- Select the Python version in the Status Bar and pick the .venv interpreter.
- Check .vscode/settings.json for python.defaultInterpreterPath or a python-envs.pythonProjects entry pointing elsewhere.
- Check launch.json for a python property if only debugging uses the wrong interpreter.
- Close old terminals and open a new one.

How to deactivate venv in VS Code
- Type
deactivatein the terminal and press Enter; the (.venv) prefix disappears. - To stop automatic activation, set python-envs.terminal.autoActivationType to off and restart your terminals.
- To remove the environment completely, right-click it in Environment Managers and select Delete.
- Select another interpreter afterwards, because projects that used the deleted environment need a new one.
Best practices for managing virtual environments in VSCode
| Practice | Why |
|---|---|
| One environment per project, named .venv | VS Code finds ./**/.venv automatically and prefers it over global interpreters |
| Keep .venv out of Git | Since Python 3.13, venv creates a .gitignore inside the environment by default |
| Keep a requirements.txt | pip freeze > requirements.txt lets anyone rebuild the environment, and VS Code installs from it on create |
| Recreate instead of moving | Environments contain absolute paths and break when moved |
| Commit .vscode/settings.json for teams | Project settings store the environment manager, not machine-specific paths |
Additional tips for VS Code virtual environments
| Tip | How |
|---|---|
| Load environment variables from a .env file | Set python.terminal.useEnvFile to true; variables are injected when terminals open |
| Different venvs for different folders | Right-click a folder in the Explorer and select Add as Python Project, then assign its environment |
| Faster installs | Install uv; venv installs then use uv pip while python-envs.alwaysUseUv is on |
| Run a selection in the venv | Select lines and press Shift+Enter to send them to the Python terminal |
| Open a Python REPL in the venv | Run Python: Start Terminal REPL from the Command Palette |
Activate venv in VS Code FAQ
How do I activate venv in the VS Code terminal?
Run .venv\Scripts\Activate.ps1 in a PowerShell terminal or .venv\Scripts\activate.bat in Command Prompt on Windows. On macOS and Linux, run source .venv/bin/activate. The prompt then starts with (.venv).
Does VS Code activate venv automatically?
Yes. After you pick the venv with Python: Select Interpreter, each new integrated terminal runs the activation command for you. Terminals opened earlier are not changed, so open a new one after switching.
How do I select a virtual environment in VS Code?
Press Ctrl+Shift+P, run Python: Select Interpreter and choose the interpreter inside your .venv folder. You can also select the Python version in the Status Bar to switch environments.
Why can't I activate venv in PowerShell?
PowerShell blocks Activate.ps1 when your execution policy does not allow local scripts. Use activate.bat in a Command Prompt terminal, or run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser as Python's documentation suggests.
How do I know if venv is activated?
The terminal prompt shows (.venv), and python -c "import sys; print(sys.prefix != sys.base_prefix)" prints True. The VIRTUAL_ENV variable is also set to the environment's path while it is active.
How do I deactivate a venv in VS Code?
Type deactivate in the terminal and press Enter. To stop VS Code activating it automatically, set python-envs.terminal.autoActivationType to off and restart your terminals.
Do I need to activate venv to run Python in VS Code?
No. Run and Debug use the selected interpreter whether or not a terminal is activated. Activation only changes which python and pip commands the terminal runs.
What is the difference between .venv and venv folders?
Only the name. Both are conventional names for a virtual environment folder, and VS Code checks workspace-local .venv and venv folders before global interpreters when it picks one automatically.
Final tips for using venv in VS Code
Create the environment with Python: Create Environment, name it .venv, and let VS Code activate it in new terminals instead of typing activation commands. That route selects the interpreter for Run, Debug and IntelliSense at the same time as the terminal, so the editor and the shell never disagree about which Python they use.





