A virtual environment “not working” is one of a handful of distinct problems that look alike: the activation command is wrong for your shell, PowerShell is blocking the script, the environment activated but python still resolves elsewhere, or the environment was built on a Python that has since moved. Each shows up differently if you know what to look at, and each takes a minute to fix.
Step 1: which shell, which command#
| Shell | Command |
|---|---|
| bash, zsh (macOS, Linux, Git Bash) | source .venv/bin/activate |
| Windows cmd | .venv\Scripts\activate.bat |
| PowerShell | .venv\Scripts\Activate.ps1 |
| fish | source .venv/bin/activate.fish |
Two mistakes cover most activation failures. Running the bash form on Windows: bin does not exist there, it is Scripts. And running ./activate without source: it executes in a subshell and changes nothing in yours. If the prompt does not gain a (.venv) prefix, activation did not happen.
PowerShell blocks the script#
.venv\Scripts\Activate.ps1 : File cannot be loaded because running scripts is disabled on this system.
PowerShell’s execution policy refuses to run unsigned scripts by default. Loosen it once, for your user account only:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Then run the activation again. This does not need administrator rights and does not affect other users. If you cannot change the policy, use cmd’s activate.bat instead, or skip activation as described at the end.
Activated, but the wrong Python runs#
(.venv) $ which python # macOS/Linux: should be .../.venv/bin/python
(.venv) $ where.exe python # Windows: .venv\Scripts\python.exe should be first
(.venv) $ python -c "import sys; print(sys.prefix)"
If the answer is somewhere other than the .venv folder, activation set the PATH but something outranks it:
- An alias.
alias python=/usr/bin/python3in your shell profile wins over PATH. Check withtype pythonand remove the alias. - A pyenv or conda shim ahead of the environment on the PATH. Deactivate conda’s base environment (
conda deactivate) or use the environment’s full interpreter path. - The Windows Store alias, which sits early in the PATH. Turn it off under Settings, Apps, App execution aliases.
Until it is fixed, .venv/bin/python (or .venv\Scripts\python.exe) called by full path always runs the right one.
Packages missing after activation#
You activated, installed with pip, and the import fails. Either pip installed elsewhere — run python -m pip install rather than bare pip, so it follows the interpreter — or the editor is using a different interpreter from the terminal. In VS Code, Python: Select Interpreter and choose the one inside .venv.
The environment broke#
bash: .venv/bin/python: No such file or directory
No Python at 'C:\Users\you\AppData\Local\Programs\Python\Python312\python.exe'
A virtual environment is not a copy of Python; it contains links to the interpreter that created it, plus your packages. Three things break the link:
- The Python it was built on was uninstalled or upgraded in place.
- The project folder was moved or renamed — the activation script and the launchers contain the old absolute path.
- Homebrew upgraded Python underneath it on a Mac.
Environments are disposable. Recreate rather than repair:
rm -rf .venv # or delete the folder in Explorer
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
If there is no requirements.txt and the old environment still partly works, .venv/bin/python -m pip freeze > requirements.txt first. Going forward, keep one committed; the whole point is that the environment can be rebuilt in a minute.
venv module missing#
The virtual environment was not created successfully because ensurepip is not available.
Debian and Ubuntu package venv separately: sudo apt install python3-venv, then try again. On other systems this usually means a broken Python install; reinstall it.
Skipping activation#
Activation only edits your shell’s PATH and prompt. Calling the environment’s interpreter directly does everything activation does, with nothing to get wrong:
.venv/bin/python app.py
.venv/bin/python -m pip install requests
.venv\Scripts\python.exe app.py # Windows
Scripts, cron jobs and CI should always do this. For interactive work, uv run does the same automatically, which is one of the main reasons people switch to uv.
Questions people ask#
Why does the prompt show (.venv) but nothing works?
The prompt is changed by the activation script regardless of whether the PATH change took effect. Check sys.prefix, not the prompt.
Can I move a virtual environment?
No. Recreate it in the new location from the requirements file.
Do I need to activate for VS Code?
No. Select the interpreter inside .venv and VS Code activates it in new terminals and uses it to run code.
venv, virtualenv, conda or uv?
venv is built in and enough for most projects. virtualenv is its older, slightly faster cousin. conda manages non-Python dependencies too, for scientific work. uv wraps venv with speed and a no-activation workflow.
Where to go next#
- Python virtual environments — the concepts.
- Python not working in the VS Code terminal — the editor side.
- uv vs pip — environments without activation.