python install_error ai_generated true

ModuleNotFoundError:没有名为 'pip' 的模块

ModuleNotFoundError: No module named 'pip'

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

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-06-04首次发现

版本兼容性

版本状态引入弃用备注
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 60% 失败

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

  2. 95% 失败

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