Python 3.11安装PyMongo失败主因是pip版本过低(

Python 3.11 的 cp311 标签不被旧版 pip 识别
pip 22.3 之前版本(比如 21.3.1)压根不认识 cp311 这个轮子标签,看到 PyMongo 或 multidict 发布的 pymongo-4.8.1-cp311-cp311-win_amd64.whl 就直接跳过,转而下载 .tar.gz 源码包。这不是包不兼容,是 pip “看不见”二进制轮子。
验证方法:pip debug --verbose 输出里搜 cp311,没出现就说明 pip 太老。
- 升级必须用
python -m pip install --upgrade pip,避免 pip 自锁 - 国内网络下,升级后仍可能因镜像源缓存旧索引而拉不到 cp311 轮子,可加
-i https://pypi.tuna.tsinghua.edu.cn/simple/ - Mac/Linux 用户注意:manylinux 标签有变体,
manylinux_2_17兼容 CentOS 7,manylinux_2_28需要 glibc 2.28+,别下错
旧包本身不支持 Python 3.11(比如 guidedlda)
像 guidedlda==2.0.0.dev22 这种 2017 年发布的包,setup.py 里硬编码了 python_requires=">=3.4, ,pip 检查到当前是 <code>3.11 就直接拒绝构建,连编译步骤都不会触发。
错误日志里如果出现 Preparing metadata (setup.py) done 后立刻报 subprocess-exited-with-error,且没有 C 编译器相关提示,大概率就是这个原因。
立即学习“Python免费学习笔记(深入)”;
- 查兼容性最快方式:去 PyPI 页面看该项目的
Classifiers或python_requires字段 - 不要强行
--force-reinstall,它绕不过python_requires检查 - 替代方案有限:找 fork 维护版、改源码(风险高)、或降级 Python(不推荐)
构建工具链缺失导致 bdist_wheel 失败
invalid command 'bdist_wheel' 不是命令写错了,而是环境里根本没装 wheel 包,或者 setuptools 版本太低()。尤其在 CI 环境或精简 Docker 镜像里常见。
更隐蔽的情况是:wheel 包存在,但 get_abi_tag 导入失败——这是 wheel 和 setuptools 版本不匹配的典型症状,比如 wheel==0.44.0 和旧 setuptools 冲突。
- 先运行
pip list | grep -E "(wheel|setuptools)"确认版本 - 安全组合:升级到
setuptools>=68.0+wheel>=0.43.0 - Windows 下若报
[WinError 2] The system cannot find the file specified,基本是缺 Visual Studio Build Tools
pyproject.toml 项目依赖解析失败
现代包(如新版 aiohttp)用 pyproject.toml 定义构建系统,pip 安装时会先跑 get_requires_for_build_wheel 获取构建依赖。如果其中某个依赖(比如 setuptools-scm)不支持 3.11,整个流程就会卡在“Getting requirements to build wheel”阶段。
错误堆栈里若出现 ImportError: cannot import name 'get_abi_tag' from 'wheel.bdist_wheel',说明构建依赖链里某个包调用了已移除的内部 API。
- 临时解法:加
--no-build-isolation让 pip 复用当前环境已有包(慎用,可能污染) - 长期解法:在
requirements.txt中显式锁定构建依赖版本,例如setuptools-scm==7.3.5 - 不要盲目升级所有构建依赖,有些新版本反而删了对旧 Python 的支持


















