You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Python build过程中的pip使用指定pip.ini配置文件?

解决隔离环境下Python包构建的SSL证书验证错误

当使用python -m build的隔离环境构建时,全新的虚拟环境不会自动读取你常规环境的pip.ini配置,因此需要通过以下方式让构建过程中的pip加载你的配置:

方法1:通过环境变量指定pip配置文件

构建工具的隔离环境会继承当前shell的环境变量,你可以先设置PIP_CONFIG_FILE指向你的pip.ini路径,再执行构建命令:

Windows系统

set PIP_CONFIG_FILE=C:\你的pip.ini所在路径\pip.ini
python -m build

Linux/macOS系统

export PIP_CONFIG_FILE=/你的pip.ini所在路径/pip.ini
python -m build

方法2:直接传递pip参数给build命令

使用--config-setting参数,将trusted-host选项直接传递给隔离环境中的pip:

python -m build --config-setting="install.trusted-host=pypi.org" --config-setting="install.trusted-host=files.pythonhosted.org" --config-setting="install.trusted-host=pypi.python.org"

或者另一种等效写法:

python -m build --config-setting="--build-option=--trusted-host=pypi.org" --config-setting="--build-option=--trusted-host=files.pythonhosted.org" --config-setting="--build-option=--trusted-host=pypi.python.org"

报错说明

你遇到的subprocess.CalledProcessError本质是隔离环境中的pip未加载常规环境的SSL信任配置,导致无法通过证书验证,上述两种方法都能让构建过程中的pip应用对应的信任主机规则。

内容的提问来源于stack exchange,提问作者user157545

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 19:18:37