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 out why the shell is resolving the wrong Python or pip.

Find python on POSIX

See which python binary your shell resolves first.

bashANYwhichpythonpath
bash
which python

A quick first check after activating a venv.

Find pip on POSIX

See which pip binary your shell resolves first.

bashANYwhichpippath
bash
which pip

Useful when `pip` appears to install into the wrong location.

Use command -v for python

Portable shell check for command resolution.

bashANYcommand-vpythonpath
bash
command -v python

Another common way to inspect command resolution in POSIX shells.

Print sys.executable

Verify the exact interpreter the shell is using.

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

This is often more trustworthy than assumptions based on PATH alone.

Use python -m pip for installs

Avoid ambiguity by tying pip to the active interpreter.

bashANYpython-m-pipbest-practicepip
bash
python -m pip install -r requirements.txt

This is a best practice when multiple Python installations are present.

Activation issues

Handle shell and Windows policy issues.

Activate using bash syntax

Source the activate script in bash or zsh.

bashANYactivatebashzsh
bash
source .venv/bin/activate

The most common activation command on POSIX systems.

Activate using fish syntax

Source the fish activation script.

bashANYactivatefish
bash
source .venv/bin/activate.fish

Use the shell-specific script when you are not using bash/zsh.

Run Activate.ps1

Activate from PowerShell.

powershellWINDOWSactivatepowershellwindows
powershell
.venv\Scripts\Activate.ps1

Standard PowerShell activation command for a venv.

Allow local PowerShell scripts

Fix execution policy for venv activation scripts.

powershellWINDOWSexecution-policypowershellwindows
powershell
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

A common resolution when PowerShell blocks `Activate.ps1`.

Refresh command hashing in zsh

Force zsh to refresh remembered command paths.

bashANYzshrehashpath
bash
rehash

Useful when a shell keeps remembering an old command location after activation.

Repair pip and packaging state

Recover from missing pip or broken packaging tools.

Install bundled pip

Bootstrap pip into the current interpreter or venv.

bashANYensurepippiprepair
bash
python -m ensurepip --default-pip

Use this when pip is missing after environment creation or corruption.

Upgrade bundled pip

Reinstall or upgrade pip from the standard library bundle.

bashANYensurepipupgraderepair
bash
python -m ensurepip --upgrade

Useful after partial uninstall or a broken pip state.

Reinstall pip packaging tools

Refresh core package tooling in the venv.

bashANYpipsetuptoolswheel
bash
python -m pip install --upgrade --force-reinstall pip setuptools wheel

A common recovery step when package operations start behaving strangely.

Purge cache during package troubleshooting

Clear cached artifacts before retrying installs.

bashANYcachepurgepip
bash
python -m pip cache purge

Useful when stale caches appear to contribute to install failures.

Full environment reset

Delete and recreate when the environment is no longer trustworthy.

Delete and recreate on POSIX

Start fresh from requirements.

bashANYresetrecreaterequirements
bash
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

Often the fastest and cleanest fix when a venv becomes inconsistent.

Delete and recreate on PowerShell

Rebuild from scratch on Windows.

powershellWINDOWSresetrecreatewindows
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

PowerShell equivalent of a full environment rebuild.

Confirm imports after rebuild

Smoke-test a rebuilt environment quickly.

bashANYsmoke-testimportsrebuild
bash
python -c "import pkgutil; print('requests' in [m.name for m in pkgutil.iter_modules()])"

A quick example of checking whether an expected package is visible after reinstall.

Recommended next

No recommendations yet.