【发布时间】:2019-01-14 12:12:34
【问题描述】:
我知道 pypi 上有一个包目录,我很想知道配置 pip 以专门在 pypi 上查找包的文件在哪里。我试图了解它的基本知识,任何相关信息都会有所帮助。
【问题讨论】:
标签: python pip python-wheel
我知道 pypi 上有一个包目录,我很想知道配置 pip 以专门在 pypi 上查找包的文件在哪里。我试图了解它的基本知识,任何相关信息都会有所帮助。
【问题讨论】:
标签: python pip python-wheel
https://pip.pypa.io/en/stable/user_guide/#configuration
pip allows you to set all command line option defaults in a standard ini style config file.
The names and locations of the configuration files vary slightly across platforms. You may have per-user, per-virtualenv or site-wide (shared amongst all users) configuration:
Per-user:
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.
There are also a legacy per-user configuration file which is also respected, these are located at:
On Unix and macOS the configuration file is: $HOME/.pip/pip.conf
On Windows the configuration file is: %HOME%\pip\pip.ini
You can set a custom path location for this config file using the environment variable PIP_CONFIG_FILE.
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
Site-wide:
On Unix the file may be located in /etc/pip.conf. Alternatively it may be in a “pip” subdirectory of any of the paths set in the environment variable XDG_CONFIG_DIRS (if it exists), for example /etc/xdg/pip/pip.conf.
On macOS the file is: /Library/Application Support/pip/pip.conf
On Windows XP the file is: C:\Documents and Settings\All Users\Application Data\pip\pip.ini
On Windows 7 and later the file is hidden, but writeable at C:\ProgramData\pip\pip.ini
Site-wide configuration is not supported on Windows Vista
If multiple configuration files are found by pip then they are combined in the following order:
The site-wide file is read
The per-user file is read
The virtualenv-specific file is read
【讨论】:
我对默认包索引有同样的问题。我们当然可以在pip.ini 文件中或在命令行中使用--index-url 选项覆盖它,但这并不能解释pypi.org 默认配置的位置。
所以我去了源代码,结果发现它是硬编码的。 我在至少两个活动源文件中看到它:
This commit 默认值在 2018 年更改。它显示了许多其他硬编码的测试和文档文件。
【讨论】: