python install_error ai_generated true

没有名为 pip 的模块 # 在:python -m venv .venv && source .venv/bin/activate && pip install requests 之后

No module named pip # after: python -m venv .venv && source .venv/bin/activate && pip install requests

ID: python/pip-venv-without-pip

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

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

venv 使用 --without-pip 创建,或 ensurepip 不可用(Debian 的 python3-venv 分离包),因此新环境没有 pip。

English

The venv was created with --without-pip, or ensurepip is unavailable (Debian's python3-venv split package), so the new environment has no pip.

generic

解决方案

  1. 95% 成功率
    python -m ensurepip --upgrade
    python -m pip install --upgrade pip
  2. 97% 成功率
    sudo apt install python3-venv python3-pip
    rm -rf .venv
    python3 -m venv .venv
    source .venv/bin/activate
    python -m pip install requests

无效尝试

常见但无效的做法:

  1. 95% 失败

    pip is the thing that is missing; the command cannot run.

  2. 80% 失败

    Mixes system and venv paths, leading to subtle import and shebang issues.