pip 配置文件详解
source link: https://www.lfhacks.com/tech/python-pip-config/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
pip
的配置文件 pip.conf
用来规定 pip
的行为,有哪些实用的配置项?配置文件一般放在什么地方生效? 本文简单介绍一下。
pip 的命令行选项
为了更好的理解 pip
的配置文件,我们有必要先来看看 pip
的命令行,本文使用的 pip
是 20.0.2 版本:
pip
的帮助文档可以用 pip -h
来查看:
$ pip -h Usage: pip <command> [options] Commands: install Install packages. download Download packages.... 此处省略 N 行 General Options: -h, --help Show help. --isolated Run pip in an isolated mode... 此处省略 N 行
可以看到有一些选项,类似:--isolated
,除了主命令的选项外,每个子命令也有命令行,比如:
$ pip install --help Usage: pip install [options] <requirement specifier> [package-index-options] ... pip install [options] -r <requirements file> [package-index-options] ... ... 此处省略 N 行 Description: ... 此处省略 N 行 Install Options: -r, --requirement <file> Install from the given requirements file. ... 此处省略 N 行 Package Index Options: -i, --index-url <url> Base URL of the Python Package Index --extra-index-url <url> Extra URLs of package indexes to ... 此处省略 N 行
每个选项都有完整版本(前面有两个-
号的)和简略版本(前面只有一个-
号的)
在执行 pip
时,命令行里为这些选项赋值,比如:
$ pip install --extra-index-url https://some-url
如果选项太多,写在命令行里明显不方便,而且也不便于重复调用。这里就用到了配置文件 pip.conf
pip 的配置文件的作用
pip
的配置文件,就是为命令行选项赋值,采用完整版本的选项名称。比如:
extra-index-url = https://some-url
$ pip install --extra-index-url https://some-url
pip 的配置文件的结构
pip.conf
是 *.ini
文件的结构,以子命令为章节名,除此之外,还有一个 global
:
[global]timeout = 60 [install]timeout = 600 [freeze]timeout = 6 [list]format = columns
如果子命令的章节里没有规定,那么就取 global
节中的参数值。
布尔值,也就是开关的值,用 true/false
或者 yes/no
都可以
pip 的配置文件的例子
下面是一个 pip.conf
的例子:
[global]index-url = http://some-index/pypi extra-index-url = https://some-extra-index/pypi https://another-extra-index/pypi http://yet-another-extra-index/pypi disable-pip-version-check = true trusted-host = some-index some-extra-index another-extra-index yet-another-extra-index timeout = 600retries = 10 [list]format = columns [freeze]no-color = yes
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK