离线环境pip安装包提示找不到setuptools,但该包已安装,求解决
问题描述
在无网络连接的系统上,尝试使用本地存储的wheel和tar.gz格式包安装Python包,执行如下命令:
pip install --no-index -f . --no-cache-dir curio
出现报错:
Looking in links: . Processing c:\users\gabe2\projects\corrosion\dist\send\curio-1.6.tar.gz Installing build dependencies ... error error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [3 lines of output] Looking in links: . ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none) ERROR: No matching distribution found for setuptools>=40.8.0 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
核心报错信息:
ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none) ERROR: No matching distribution found for setuptools>=40.8.0
但当前环境已安装setuptools 65.5.0,pip list输出可确认:
Package Version ------------- -------------- async-helpers 1.0 hanna-meter 2024.5.19.dev3 pip 23.2.1 setuptools 65.5.0
本地已备齐的文件:
async_helpers-1.0-py3-none-any.whl* hanna_meter-2024.5.19.dev3-py3-none-any.whl* curio-1.6.tar.gz* venv/
原因分析
使用--no-index -f .参数时,pip会强制从指定的本地目录查找所有依赖(包括构建依赖),即便系统中已安装满足版本要求的包。curio是源码包(tar.gz),安装前需要构建,pip会启动独立子进程处理构建依赖的安装,该子进程的pip只会从你指定的本地目录查找setuptools,而你的本地目录中没有setuptools的wheel或源码包,因此触发报错。
解决步骤
方法一:补充setuptools本地包到指定目录
- 从有网络环境下载对应Python版本的setuptools wheel包(例如
setuptools-65.5.0-py3-none-any.whl) - 将该包放到执行pip命令的本地目录(即
-f .指定的当前目录) - 重新执行原安装命令:
pip install --no-index -f . --no-cache-dir curio
方法二:跳过构建依赖隔离
使用--no-build-isolation参数,让pip直接使用当前环境已安装的setuptools进行构建,无需单独安装构建依赖:
pip install --no-index -f . --no-cache-dir --no-build-isolation curio
此方法更简便,适合已确认当前环境setuptools版本满足要求的场景。
内容的提问来源于stack exchange,提问作者Mike
相关产品推荐
相关产品推荐

