python install_error ai_generated true

/path/to/venv/bin/python: No module named pip

ID: python/pip-venv-no-pip

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-11-28First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

Root Cause

A virtual environment was created without pip (e.g. python -m venv --without-pip, or a broken ensurepip), so pip is unavailable inside it.

generic

中文

创建虚拟环境时未包含 pip(例如 python -m venv --without-pip,或 ensurepip 损坏),因此环境内无法使用 pip。

Workarounds

  1. 95% success
    source /path/to/venv/bin/activate
    python -m ensurepip --upgrade
    python -m pip install --upgrade pip
  2. 98% success
    deactivate || true
    rm -rf /path/to/venv
    python -m venv /path/to/venv
    source /path/to/venv/bin/activate
    python -m pip --version

Dead Ends

Common approaches that don't work:

  1. 95% fail

    pip is not importable inside the venv, so the command itself fails before it can install anything.

  2. 90% fail

    Installs pip for the system Python, not for the broken virtual environment.