gpt4 book ai didi

python - pip 8.1 的自定义 pip.conf 位置

转载 作者:行者123 更新时间:2023-12-04 18:28:57 25 4
gpt4 key购买 nike

我使用 Python 3.5 和 pip 8.1.1 作为操作系统包的一部分管理一组 Ubuntu 16.04 服务器。服务器无法访问 Internet 和 pip需要配置内部pypi镜像。

我在 /home/hanxue/.config/pip/pip.conf 有以下配置文件

[global]
index-url = https://pypimirror/simple
cert = /etc/ssl/certs/ca-certificates.crt

不幸的是 pip 8.1.1 没有读取位于 ~/.config/pip/pip.conf 的配置文件。 .只有 >10 及更高版本的 pip 使用更一致的 XDG 路径 ~/.config/pip/pip.conf
我试过设置 PIP_CONFIG_FILE环境变量,但 pip 8.1.1 没有捡起它
$ PIP_CONFIG_FILE=/home/hanxue/.config/pip/pip.conf /usr/bin/pip3 search tensorflow

我知道我可以在 ~/.pip/pip.conf 创建文件的副本解决问题。但这是针对最终用户的,他们最终会得到 2 pip.conf从而在路上产生困惑。例如,编辑 ~/.pip/pip.conf但发现 pip 19/python 3.6 不接受设置。

如何让 pip 8.1 从非标准位置获取配置?

最佳答案

pip 9.0 及更高版本

如果你现在使用的是最新版本的pip,或者9.0.0以上的任何版本,配置文件应该在~/.config/pip/pip.conf .根据 official pip user guide :

On Unix the default configuration file is: $HOME/.config/pip/pip.conf which respects the XDG_CONFIG_HOME environment variable.

On macOS the configuration file is $HOME/Library/Application Support/pip/pip.conf if directory $HOME/Library/Application Support/pip exists else $HOME/.config/pip/pip.conf.

On Windows the configuration file is %APPDATA%\pip\pip.ini.



文档明确指出 $HOME/.pip/pip.conf是旧路径, configuration file function in pip's source is similarly named legacy .

pip 8.x.x 及更早版本

告诉 pip 你的配置文件位于 $HOME/.config/pip/pip.confPIP_CONFIG_FILE环境变量
$ PIP_CONFIG_FILE=~/.config/pip/pip.conf /usr/bin/pip3 install --user colorama
Collecting colorama

已经在 Ubuntu 16.04 上使用 pip 8.1.1 和在 CentOS 7.4 上使用 pip 8.1.2 进行了测试

关于python - pip 8.1 的自定义 pip.conf 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57326036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com