pip.conf可以同时指定两个index-url吗?

Can pip.conf specify two index-url at the same time?

我尝试在 pip.conf 中使用带索引 url 的 pip。但是,我不能确保我们可以获得所有必要的 python 库。所以,我想知道 pip 支持是否在 pip.conf.

[global] 部分指定了多个 index-url

如果您需要多个包索引,则必须使用 --extra-index-url

来自pip man page

   -i,--index-url <url>
          Base URL of Python Package Index (default https://pypi.python.org/simple/).

   --extra-index-url <url>
          Extra URLs of package indexes to use in addition to --index-url.

pip.conf 中,设置名称必须没有 --。来自 documentation:

The names of the settings are derived from the long command line option, e.g. if you want to use a different package index (--index-url) and set the HTTP timeout (--default-timeout) to 60 seconds your config file would look like this:

[global]
timeout = 60
index-url = http://download.zope.org/ppix

因此您可以添加 pip.conf

extra-index-url = http://myserver.com/pip

在您的 pip.conf 中,您还必须将两个索引主机都添加为受信任的,因此看起来像这样:

[global]
index-url = http://download.zope.org/simple
trusted-host = download.zope.org
               pypi.org
               secondary.extra.host
extra-index-url= http://pypi.org/simple
                 http://secondary.extra.host/simple

在此示例中,您有一个主索引和两个额外的索引 url,并且所有主机都是可信的。

如果您没有将主机指定为受信任的主机,您将收到以下错误:

The repository located at secondary.extra.host is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host secondary.extra.host'.

干杯!

正在将 radtek 的答案更新为 pypi 的新 URL。

改为https://pypi.org

因此,为了让您的 pip 能够回退到原始的 pypi 服务器,您需要添加“https://pypi.org/simple”作为额外索引-url,同时将您的本地服务器保持为指数-url。 不要忘记将两者都添加到您的 "trusted-host" 列表

此更新基于 onelaview: "Official PyPI now supports HTTPS so you can specify https://pypi.org/simple/ 对 extra-index-URL 的注释,避免在 trusted-host 中指定 pypi.org。


因此您的 pip.conf 需要包含以下内容:

[global]
index-url = https://somedomain.org/simple
trusted-host = somedomain.org
               pypi.org
               secondary.extra.host
extra-index-url= http://pypi.org/simple <= either one of these is fine
                 https://pypi.org/simple <= either one of these is fine
                 http://secondary.extra.host/simple

您也可以通过设置环境变量来实现:

export PIP_EXTRA_INDEX_URL=http://localhost:8080/simple/

相当于

[global]
extra-index-url = http://localhost:8080/simple/

但不需要 pip.conf 文件