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

Pip

Pip Problem Overview


I have tried using pip with index-url in pip.conf. However, i can not make sure that we can get all the necessary python library. So, i want to know if pip support specify more than one index-url in [global] section in pip.conf.

Pip Solutions


Solution 1 - Pip

In your pip.conf, you will also have to add both of the index hosts as trusted, so would look something like this:

[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

In this example, you have a primary index and two extra index urls and all hosts are trusted.

If you don't specify the host as trusted, you will get the following error:

> 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'.

Cheers!

Solution 2 - Pip

If you want more than one package index you have to use the --extra-index-url

From the 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.

In pip.conf the name of settings must be put without --. From the 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

So you can add in your pip.conf

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

Solution 3 - Pip

updating radtek 's answer with the new URL to pypi.

It changed to https://pypi.org

So for your pip to be able to fall back to the original pypi server you'll need to add "https://pypi.org/simple" as an extra-index-url while keeping your local server as index-url. Don't forget to add both to your "trusted-host" list

This update is based on the comment of onelaview: "Official PyPI now supports HTTPS so you can specify https://pypi.org/simple/ for extra-index-URL and avoid specifying pypi.org in trusted-host."


So your pip.conf needs to be containing the following:

[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

Solution 4 - Pip

You can also do this by setting an environment variable:

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

which is equivalent to

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

but does not require a pip.conf file

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionandyView Question on Stackoverflow
Solution 1 - PipradtekView Answer on Stackoverflow
Solution 2 - PipOrtomala LokniView Answer on Stackoverflow
Solution 3 - PipstudiojView Answer on Stackoverflow
Solution 4 - PipTomasz BartkowiakView Answer on Stackoverflow