Python venv Troubleshooting Cheat Sheet

Diagnose activation problems, broken pip, wrong interpreter selection, PATH confusion, and environment drift in Python virtual environments.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Wrong interpreter or pip
Find python on POSIX
which python

# See which python binary your shell resolves first.

Find pip on POSIX
which pip

# See which pip binary your shell resolves first.

Use command -v for python
command -v python

# Portable shell check for command resolution.

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

# Verify the exact interpreter the shell is using.

Use python -m pip for installs
python -m pip install -r requirements.txt

# Avoid ambiguity by tying pip to the active interpreter.

## Activation issues
Activate using bash syntax
source .venv/bin/activate

# Source the activate script in bash or zsh.

Activate using fish syntax
source .venv/bin/activate.fish

# Source the fish activation script.

Run Activate.ps1
.venv\Scripts\Activate.ps1

# Activate from PowerShell.

Allow local PowerShell scripts
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

# Fix execution policy for venv activation scripts.

Refresh command hashing in zsh
rehash

# Force zsh to refresh remembered command paths.

## Repair pip and packaging state
Install bundled pip
python -m ensurepip --default-pip

# Bootstrap pip into the current interpreter or venv.

Upgrade bundled pip
python -m ensurepip --upgrade

# Reinstall or upgrade pip from the standard library bundle.

Reinstall pip packaging tools
python -m pip install --upgrade --force-reinstall pip setuptools wheel

# Refresh core package tooling in the venv.

Purge cache during package troubleshooting
python -m pip cache purge

# Clear cached artifacts before retrying installs.

## Full environment reset
Delete and recreate on POSIX
rm -rf .venv && python -m venv .venv && source .venv/bin/activate && python -m pip install -U pip setuptools wheel && python -m pip install -r requirements.txt

# Start fresh from requirements.

Delete and recreate on PowerShell
Remove-Item -Recurse -Force .venv; py -m venv .venv; .venv\Scripts\Activate.ps1; python -m pip install -U pip setuptools wheel; python -m pip install -r requirements.txt

# Rebuild from scratch on Windows.

Confirm imports after rebuild
python -c "import pkgutil; print('requests' in [m.name for m in pkgutil.iter_modules()])"

# Smoke-test a rebuilt environment quickly.

Recommended next

No recommendations yet.