python
module_error
ai_generated
true
ModuleNotFoundError:python -m venv .venv && source .venv/bin/activate 后找不到名为 'pip' 的模块
ModuleNotFoundError: No module named 'pip' after python -m venv .venv && source .venv/bin/activate
ID: python/pip-venv-no-pip-ensurepip-missing
80%修复率
89%置信度
0证据数
2024-04-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
创建 venv 时未包含 pip。这发生在 Debian/Ubuntu 上未安装 python3-venv 时,或使用 --without-pip 创建 venv 时,或某些最小化 Docker 镜像中。
English
The venv was created without pip. This happens on Debian/Ubuntu when python3-venv is not installed, or when venv is created with --without-pip, or on some minimal Docker images.
解决方案
-
95% 成功率
rm -rf .venv && python3 -m venv .venv && source .venv/bin/activate && python -m pip --version
-
90% 成功率
python -m ensurepip --upgrade
-
92% 成功率
sudo apt update && sudo apt install python3-venv python3-pip
无效尝试
常见但无效的做法:
-
95% 失败
pip is not available to install itself; the module is missing.
-
85% 失败
Installs pip for the system interpreter, not inside the venv.