python install_error ai_generated true

ModuleNotFoundError: No module named 'pip'

ID: python/pip-venv-pip-missing-after-ensurepip

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-06-04First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

Root Cause

A venv was created with `--without-pip`, or ensurepip failed silently, leaving the environment without pip installed.

generic

中文

venv 以 `--without-pip` 创建,或 ensurepip 静默失败,导致环境未安装 pip。

Workarounds

  1. 90% success
    Bootstrap pip via get-pip.py: `curl -sS https://bootstrap.pypa.io/get-pip.py | python`.
  2. 95% success
    Recreate the venv without --without-pip: `rm -rf .venv && python -m venv .venv`.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    On some distros (Debian/Ubuntu) ensurepip is disabled and prints a message suggesting apt install python3-pip instead.

  2. 95% fail

    pip is the module being invoked; the command cannot run before pip exists.