debugpythonModeratepending
Debug: Python virtual environment not activating correctly
Viewed 0 times
venvvirtual environmentactivatewrong pythonpip path
Error Messages
Problem
Python virtual environment doesn't activate properly, or the wrong Python/pip is used after activation.
Solution
Diagnose venv issues:
# 1. Verify which Python is being used
which python3
which pip
python3 -c 'import sys; print(sys.executable)'
python3 -c 'import sys; print(sys.prefix)'
# 2. Check if venv is activated
echo $VIRTUAL_ENV # Should show path to venv
# 3. Common issues:
# Issue: 'source activate' fails
# Wrong path!
source .venv/bin/activate # Linux/macOS
source .venv/Scripts/activate # Windows Git Bash
.venv\Scripts\activate # Windows CMD
# Issue: Wrong Python version in venv
# Create with specific Python
python3.11 -m venv .venv # Uses Python 3.11
# Issue: pip installs to system instead of venv
# Verify pip is from venv
pip --version # Should show .venv path
# If not, use:
python3 -m pip install package # Guaranteed to use venv's pip
# Issue: venv broken after Python upgrade
# Recreate the venv
rm -rf .venv
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Issue: IDE using wrong interpreter
# VS Code: Ctrl+Shift+P > Python: Select Interpreter
# Choose: .venv/bin/python3
# 4. Nuclear option: fresh start
deactivate 2>/dev/null
rm -rf .venv __pycache__ *.egg-info
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtWhy
Virtual environment issues usually stem from path conflicts, wrong Python version, or system Python shadowing the venv's Python.
Context
Python development environment setup
Revisions (0)
No revisions yet.