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

65,994

Solution 1

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

Solution 2

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
Share:
65,994

Related videos on Youtube

selethen
Author by

selethen

Updated on December 02, 2021

Comments

  • selethen
    selethen over 2 years

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

  • Chris Maes
    Chris Maes about 4 years
    The OP wants to download from his mirror by default, extra-index-url will still use pypi.org, which is not what he wants.
  • Tejaswa
    Tejaswa about 4 years
    that's why i said after the code block "In case if you want pip to look into your URL first then switch the places of url on above options."
  • selethen
    selethen about 4 years
    It works, except on the third line it should be pip config --user set global.trusted-host my-company instead of what you wrote (without the equals char).
  • RufusVS
    RufusVS almost 3 years
    I think you should edit this answer, adding another file example showing what you mean by "switching places" because I'm not sure it is immediately clear to everyone what you're saying. I had to reread it several times myself.
  • studioj
    studioj over 2 years
    as a side note it makes sense to use a https server, most custom pypi implementations provide https as well as http for backwards compatibility, but https provides encrypted communication for authentication etc. @chris-maes I would suggest to adjust this in your answer