VS Code

How to Activate Venv in VSCode for Python

How to Activate Venv in VSCode for Python

Open the Command Palette, run Python: Select Interpreter, pick your .venv, then open a new integrated terminal. That covers most people. If you’d rather do it by hand, run source .venv/bin/activate on macOS or Linux, or .venv\Scripts\Activate.ps1 in Windows PowerShell.

Under the hood, activation just puts the environment’s bin or Scripts folder at the front of PATH. So python and pip resolve to the project’s venv instead of the global install.

The interpreter picker and the terminal are not the same thing, though, and this trips people up all the time. The selected interpreter handles running, debugging and IntelliSense. The terminal follows python-envs.terminal.autoActivationType, which defaults to command in the VS Code documentation dated 02/04/2026.

Python’s own documentation adds that a venv works without activation when you call its interpreter by full path.

Picking an activation method in VSCode

Most of the time I select the interpreter once and let the Python extension activate the venv in every new terminal. Running the activate script yourself in the integrated terminal still works, and sometimes you’ll need it.

Activation doesn’t do much, honestly. It prepends the environment’s bin (POSIX) or Scripts (Windows) folder to PATH, so python and pip resolve to the venv copies, and it sets the VIRTUAL_ENV environment variable.

MethodWhat it changesScopeBest for
Terminal scriptPATH and promptOne terminal sessionOne-off shells, pip and CLI tools
Select InterpreterPython used by the editorWhole workspaceIntelliSense, running, debugging
Automatic activationTerminal environment on openEvery new terminalDaily project work

The interpreter picker steers the editor. The terminal is a separate shell, and how the environment reaches it depends on which mechanism you’re on.

The Python Environments extension’s default command mode types the activation command into each new terminal. The Python extension’s environment-variable mode is different: no activation command runs at all, and the environment gets applied by setting environment variables instead.

That second mechanism has a side effect people don’t expect. The usual prompt indicator may not change even when the environment is active. So a missing (.venv) prefix does not prove the venv is off.

Python’s documentation goes a step further and says you don’t need to activate a virtual environment at all, because calling the environment’s Python by its full path works. Fine for one command. Tiresome for a whole session.

My advice is to select the interpreter once per project and let new terminals follow it. Reach for the manual script only when a terminal ignores the selection.

How to create a venv in VSCode

YouTube player

Run python -m venv .venv in the project root. Or open the Command Palette, run Python: Create Environment and choose Venv. You get the same kind of folder either way.

Creating from the terminal

The venv module creates the target directory and places a pyvenv.cfg file in it. Inside the folder you’ll find:

  • pyvenv.cfg, a config file whose home key points to the Python installation that ran the command
  • a bin folder (Scripts on Windows) with a copy or symlink of the Python executable, plus the activate scripts
  • a lib/pythonX.Y/site-packages subdirectory (Lib\site-packages on Windows), which is where pip installs packages

Keep the folder at the workspace root and name it .venv or venv. The extension checks for a workspace-local .venv or venv before it looks at any global interpreter.

Creating from the Command Palette

Press Ctrl+Shift+P (Cmd+Shift+P on macOS), run Python: Create Environment, pick Venv, then choose a Python interpreter for the environment.

Custom Create asks you for a manager (venv or conda), a Python version, a name, and whether to install dependencies.

Quick Create skips the questions. It’s the + button in the Environment Managers view, and it uses your default manager (venv unless you change python-envs.defaultEnvManager), the latest available Python and a .venv name (.venv-1, .venv-2 and so on if the name is taken). Then it selects the new environment for the workspace. I use this one most.

Both routes detect a requirements.txt or pyproject.toml in the workspace and install dependencies from it.

As of the VS Code environments page dated 02/04/2026, uv handles venv creation and package installation when it is installed and python-envs.alwaysUseUv is enabled. That setting is on by default.

Python 3.13, released on October 7, 2024, made venv write a .gitignore file by default. The file contains * so Git ignores the entire directory. The –without-scm-ignore-files option switches it off.

VSCode only creates two kinds of environment, venv and conda. If you haven’t settled on one yet, this venv vs conda vs poetry comparison lays out the trade-offs.

How to activate a venv in the VSCode terminal on Windows, macOS and Linux

YouTube player

On macOS and Linux it’s source .venv/bin/activate. Windows PowerShell wants .venv\Scripts\Activate.ps1, and Command Prompt wants .venv\Scripts\activate.bat. These come from the activation table in the Python documentation.

Open the integrated terminal from the Terminal menu or with Ctrl+ (Ctrl+Shift+ creates an additional terminal). Terminal: Create New Terminal opens a shell for the selected interpreter. The commands below assume it starts in the project root.

PlatformShellCommandFolder
macOS, Linuxbash, zshsource .venv/bin/activatebin
macOS, Linuxfishsource .venv/bin/activate.fishbin
WindowsPowerShell.venv\Scripts\Activate.ps1Scripts
WindowsCommand Prompt.venv\Scripts\activate.batScripts
WindowsGit Bashsource .venv/Scripts/activateScripts

The Git Bash shell on Windows takes the bash route, just with Scripts in the path instead of bin.

When it works, the prompt gains the environment name in parentheses. By default that’s the environment directory name. You can set a custom one with the –prompt option.

A bit of history, in case you’re on something old. The fish and csh scripts were added in Python 3.4, and the PowerShell scripts for POSIX came in 3.8.

If PowerShell refuses to run Activate.ps1, the execution policy is to blame. The RemoteSigned fix is in the troubleshooting section further down.

How to select the venv as the Python interpreter in VSCode

Open the Command Palette and run Python: Select Interpreter. Clicking the Python version in the status bar opens the same picker. Pick the entry that points to your .venv folder.

  1. Open the folder that contains .venv as the workspace.
  2. Press Ctrl+Shift+P (Cmd+Shift+P on macOS).
  3. Run Python: Select Interpreter.
  4. Choose the entry that lists the .venv path.
  5. Confirm the status bar now shows the venv’s Python version.

Whatever you pick here drives running, debugging and IntelliSense. The Run Python File button follows it too, since it opens a terminal where the interpreter is automatically activated before the script runs.

Haven’t picked anything? Then the extension works down a list. pythonProjects entries come first, then defaultEnvManager (only when set explicitly), then python.defaultInterpreterPath, then auto-discovery, which tries a workspace-local .venv before global interpreters.

Terminals read their configuration at startup. Open a new terminal after switching interpreters.

Sometimes the venv just isn’t in the list. Choose Enter interpreter path and paste the absolute path to the .venv folder. Users on the uv issue tracker report that the folder path worked where the python executable path did not, which is a little counterintuitive.

Switching to another environment later uses the same picker, and there is a separate guide to changing the Python interpreter in VSCode.

How to make VSCode activate the venv automatically in new terminals

The setting is python-envs.terminal.autoActivationType. It accepts command, shellStartup or off, and the default is command.

How the values differ

With command, the activation command runs visibly after the terminal opens. You actually see it typed out. It works with all shells.

shellStartup activates through shell startup scripts instead, so the environment is already active the moment the terminal appears.

off disables automatic activation.

The extension’s own guidance calls shellStartup necessary when Tasks or Copilot run commands in a new terminal. The VS Code settings reference lists it as supported for zsh, fish, pwsh, bash and cmd.

Restart open terminals after changing the value. To undo what shellStartup wrote into your startup scripts, run Python Envs: Revert Shell Startup Script Changes.

The VS Code page dated 02/04/2026 describes shellStartup as becoming the default in a future release. For now command stays the default.

Why guides contradict each other

This is where it gets confusing. The Python extension wiki (last edited January 19, 2024) says the extension activates the selected environment in the terminal by setting environment variables, without running any activation commands.

The Python Environments extension documentation (page dated 02/04/2026) describes command mode, which does run the activation command, visibly. So a guide written for one mechanism can look flat-out wrong if you’re on the other.

The environment-variable route also leans on shell integration. That’s on by default for supported shells launched from VS Code.

Older settings and settings.json

python.terminal.activateEnvironment still shows up in a lot of guides and defaults to true. When both are set, python-envs.terminal.autoActivationType takes precedence.

The interpreter has its own setting, python.defaultInterpreterPath. It applies the first time the extension loads a workspace. Changes made after an interpreter is selected are not applied.

Point it at ${workspaceFolder}/.venv and each developer’s OS-appropriate environment gets found, so settings.json can be committed to the repository.

Workspace settings live in .vscode/settings.json, and opening settings.json in VSCode takes one command.

On a normal project I’d keep it boring: .venv at the workspace root, interpreter selected once, autoActivationType left on command. Move to shellStartup only when something other than you runs commands in the terminal.

How to check that the venv is active

Run python -c "import sys; print(sys.prefix != sys.base_prefix)" in the terminal. True means you’re in a venv. Python’s documentation calls that comparison sufficient to tell whether the running interpreter is in one.

If you want more detail than True or False, these are roughly in order from quickest to slowest:

  • Hover over the terminal tab to see the active environment, or click Show environment contributions to see which variables were applied
  • Run which python on macOS, Linux and Git Bash, or where python on Windows. It should print a path inside .venv.
  • python -c "import sys; print(sys.executable)" prints the full interpreter path. The Python extension’s maintainers ask for this output when triaging bug reports, so it’s a good habit.
  • The Python channel in the Output panel records which interpreter the extension resolved

Don’t treat VIRTUAL_ENV as proof, by the way. The documentation says it cannot be relied on to determine whether a venv is in use.

When the editor and the terminal disagree, one of them points at a different Python. The usual reasons are below.

Why the venv does not activate in VSCode, and how to fix it

Most failures come down to a PowerShell execution policy, or a shell init script that activates some other environment. Automatic injection that never runs is the other big one. Occasionally the Python extension just isn’t running.

SymptomLikely causeFix
Running scripts is disabledExecution policy blocks Activate.ps1RemoteSigned for CurrentUser
Prompt shows (base)conda’s base environment activates from the shell init scriptconda config --set auto_activate_base False (newer conda releases name the key auto_activate), then restart the shell
Setting is true, terminal not activatedA script shebang pointing at python3Check sys.executable, then the shebang line
shellStartup does nothing in WSLWSL uses command activationSet autoActivationType to command

PowerShell blocks Activate.ps1

Microsoft’s documentation changed its default. Older pages list Restricted as the default for Windows client computers, and Restricted permits individual commands but will not run scripts. The current page lists RemoteSigned as the default for Windows computers. Scripts can run under that one.

So the error means your effective policy is stricter than RemoteSigned. Group Policy can set execution policies for computers and users, and Get-ExecutionPolicy -List shows every scope.

The fix is one line:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Don’t drop -Scope. Without it, the cmdlet writes to the LocalMachine scope. The CurrentUser scope affects only the user who sets it, which is usually what you want.

The terminal runs the wrong Python

  • Implicit activation fails when automatic shell integration is off and an init script activates a different environment
  • Automatic injection can fail in sub-shells and in plain ssh sessions without the Remote – SSH extension. Complex shell setups break it too.
  • A macOS user reported the venv going unused with python.terminal.activateEnvironment set to true on Python extension 2024.15. The issue closed after the script’s shebang changed from python3 to python.

Whatever the cause, which python shows what the terminal actually resolves. Trust that over the prompt.

When the extension is the problem

If the Python extension is not running when the terminal opens, the venv does not activate, and commands typed there do not involve it.

WSL is its own case. A reporter found shellStartup had no effect, and a maintainer said WSL uses command activation rather than shell activation. The issue links PR 880, a fix for activation going missing after rc scripts are modified.

Then there’s the interpreter getting rejected outright. A March 2026 report on the Python Environments extension repository describes VSCode refusing a .venv interpreter with “Unable to handle … (Source: Python Environments)” after the same steps had worked before. Read the Python log before you touch any settings.

How to deactivate a venv and keep its packages reproducible

Type deactivate in your shell. It only affects that terminal. The selected interpreter stays put, and if automatic activation is on, the next terminal you open activates the venv again.

A fuller walkthrough sits in the guide on how to exit a venv in VSCode.

Recording packages with pip freeze

pip freeze prints installed packages as name==version lines, sorted case-insensitively. Redirect that to a file and the venv becomes reproducible.

  1. Activate the venv.
  2. Run python -m pip freeze > requirements.txt.
  3. In a fresh venv, run python -m pip install -r requirements.txt.

The file holds a pinned version of everything that was installed when pip freeze was run.

One version quirk. On Python 3.11 and earlier the output omits pip, setuptools, wheel and distribute. On 3.12 and later only pip is omitted. The –all flag includes them.

For teams there’s a real limit here. pip freeze reports what is installed. It does not compute a lockfile or a solver result.

Treating the venv as disposable

When it drifts, delete it and rebuild it. Python’s documentation says a venv is not checked into source control and should be simple to delete and recreate. No project code belongs inside it.

Before Python 3.13, venv writes no ignore file, so add .venv/ to the project’s .gitignore file yourself.

Venv Activation in VSCode FAQ

Can one workspace use a different venv for each folder?

Yes. Python Projects let you assign different environments to different folders.

There’s a catch in the docs, though. Pylance uses a single interpreter per workspace, so IntelliSense follows only one environment. For a separate interpreter per folder, add the folders to a multi-root workspace.

How do I use the venv as a Jupyter notebook kernel?

Open the .ipynb file, click the kernel picker in the top right and select your .venv interpreter.

The VS Code docs note that Jupyter uses the older Python extension API for environment discovery. So its list comes from a different path than Python: Select Interpreter, and the two won’t always match.

Can VSCode switch to Poetry or pyenv environments the same way?

For switching, yes. The Python Environments extension gives one interface across venv, system-installed Python, conda, pyenv, poetry and pipenv, and uses uv for venvs when it is installed.

Creating them is another story. pyenv, poetry and pipenv environments are discovered only, so you build them with their own tools first.

Does the Python extension install Python itself?

No. It adds IntelliSense, running and debugging, but you install the Python interpreter separately.

On macOS, the system Python is not supported, and the tutorial recommends a package manager such as Homebrew.

Setting Up Venv Activation Once Per Project

For venv activation in VSCode, the setup that keeps working is a .venv folder at the workspace root, one interpreter selection, and automatic terminal activation left on its default.

Order matters, because terminal activation applies the environment chosen with Select Interpreter when a new terminal is created.

  1. Create .venv at the workspace root.
  2. Run Python: Select Interpreter once.
  3. Open a new terminal and run the sys.prefix check.

Command mode types the activation line into every terminal, which is a little noisy. shellStartup hides it, but it does that by editing your shell startup scripts, and I’m not a fan of extensions touching my .zshrc.

Verified against the VS Code documentation on November 20, 2026. A new default of shellStartup would make every terminal active at launch, and that change is the cue to revisit this setup.

With the environment active, running Python scripts in VSCode is the next step.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.