How to setup pip to download from mirror repository by default?

Question:

I am forced to download python packages from local mirror PyPi repository. I do this by using the -i and --trusted-host options. Whole installation command looks like this:

pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com package_name

Having to type in that options each time is kinda annoying though (in reality those are long URL’s). I’ve tried to create get_package.bat file (I’m working on Windows 10) with following content:

pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%1"

It works perfectly fine, although when I wanted to execute pip search command, it turned out to be useless since it has hard-coded install command and there is no way to use it with search.

Is there any way in which I can setup pip to download from mirror repository by default, so that I can execute pip install package_name or pip search package_name without any additional options?

Eventually I could try making .bat file that would take 2 parameters like this:

pip %1 -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%2"

But I wonder if there’s more "elegant" way to do this.

Asked By: selethen

||

Answers:

using pip config, on user or global level. I have /etc/pip.conf configured like this:

[global]
index=https://my-company/nexus/repository/pypi-group/pypi
index-url=https://my-company/nexus/repository/pypi-group/simple
trusted-host=my-company

but you can configure this using pip config on user or global level, something like:

pip config --user set global.index https://my-company/nexus/repository/pypi-group/pypi
pip config --user set global.index-url https://my-company/nexus/repository/pypi-group/simple
pip config --user set global.trusted-host my-company

#NOTES

Answered By: Chris Maes

Use pip3 config list -v to get list of locations where your pip.conf is located. Then go to one of the location(I prefer user) and add your URL.
The file should look like this, if empty then add the lines.

[global]
index-url=https://pypi.org/simple
extra-index-url=<your_url>

In case if you want pip to look into your URL first then switch the places of url on above options.

[global]
index-url=<your_url>
extra-index-url=https://pypi.org/simple
Answered By: Tejaswa

You could also add the -i and --trusted-host options to your requirements.txt like this:

-i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com
numpy==1.23.4
pandas==1.5.1

And then, just do:

pip install -r requirements.txt

which gives:

Looking in indexes: https://sampleurl.com/pypi-remote/simple
Collecting numpy==1.23.4
  Downloading numpy-1.23.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)
...

I found this solution to work well in case you don’t necessary want to create a pip.conf file (for example, in CIs).

Answered By: vvvvv
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.