Developer Fix

VS Code Virtual Environment Not Working? Complete Fix

If your .venv will not activate, does not appear in the interpreter list, or VS Code keeps using global Python, the environment may be damaged, blocked by the shell, or disconnected from the workspace.

Difficulty: Easy–Medium Time: 15–30 minutes Updated: July 2026 Works for: Windows / macOS / Linux

A virtual environment gives each Python project its own interpreter and packages. When it is working, installing a library in one project does not affect another. When it is not working, VS Code may silently fall back to global Python and create package errors that feel completely random.

Fix 1 — Open the project root folder

Use File → Open Folder and select the folder that contains both your code and the environment directory, usually .venv. Opening only a single Python file can prevent workspace-based environment discovery.

Fix 2 — Select the environment interpreter manually

  1. Press Ctrl + Shift + P.
  2. Run Python: Select Interpreter.
  3. Choose the interpreter inside .venv.

Windows path:

.venv\Scripts\python.exe

macOS or Linux path:

.venv/bin/python

If it is not listed, choose Enter interpreter path and select it directly.

Fix 3 — Activate the environment in a fresh terminal

Windows Command Prompt:

.venv\Scriptsctivate.bat

Windows PowerShell:

.venv\Scripts\Activate.ps1

macOS or Linux:

source .venv/bin/activate

Open a new terminal after selecting the interpreter. Old terminals may remain attached to a previous environment.

Fix 4 — Resolve PowerShell execution policy errors

If PowerShell says script execution is disabled, avoid permanently weakening security for the whole computer. A common user-level option is:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Read the prompt carefully and use a policy approved for your device. On managed systems, use Command Prompt activation or contact the administrator rather than bypassing organisational restrictions.

Fix 5 — Check that the environment points to an existing Python

Virtual environments are not fully portable. If the project folder was copied from another computer, moved after Python was removed, or restored from a backup, the environment may reference an interpreter path that no longer exists.

In that case, recreate it:

python -m venv .venv

Then reinstall dependencies:

python -m pip install -r requirements.txt

Do not commit or share the entire virtual environment folder. Share dependency files and rebuild the environment on each machine.

Fix 6 — Verify the active interpreter

python -c "import sys; print(sys.executable)"

The result should point inside .venv. Also verify pip:

python -m pip --version

If either path points outside the project environment, activation or interpreter selection is incomplete.

Fix 7 — Install packages after activation

python -m pip install package-name

Packages installed globally will not automatically appear in a clean virtual environment. That isolation is the feature, not a bug.

Fix 8 — Remove stale workspace interpreter settings

Open .vscode/settings.json and look for a saved Python executable path that no longer exists. Remove the obsolete entry, reload VS Code, and select the new .venv interpreter.

Fix 9 — Recreate a damaged environment

If activation scripts are missing or installed packages behave inconsistently, delete only the environment directory—not your source code—then rebuild it:

python -m venv .venv
.venv\Scriptsctivate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

On macOS or Linux, use the matching activation command. Keep a current requirements.txt or project configuration so rebuilding is painless.

FAQ

Why does the environment name appear but Python is still global?

The prompt text alone is not proof. Check sys.executable; a stale or customised prompt can be misleading.

Can I move a virtual environment to another folder?

It is safer to recreate it because activation scripts and interpreter references may contain absolute paths.

Should the .venv folder be uploaded to GitHub?

Usually no. Add it to .gitignore and commit dependency files instead.