Search code examples
pythonpipnexuspypi

What's the difference between Python pip's pip.conf and pypirc file?


I'm having trouble reaching a nexus server that we're using to store custom python packages. I've been told to change the settings in both my ~/.pypirc file and the ~/.pip/pip.conf file.

What's the difference between those two files in how they're used? It seems like the pip install -r requirements.txt command refers to the pip.conf file, and then the fields within the pip.conf file requires looking up the pypirc file?

Example pip.conf file:

[global]
index = https://user:[email protected]/somerepo/pypi-group/pypi
index-url = index = https://user:[email protected]/somerepo/pypi-group/simple

Example pypirc file:

[distutils]
index-servers =
    pypi
    nexus

[pypi]
repository: https://pypi.org/pypi
username: abc
password: def

[nexus]
repository: https://someurl.com/somerepo/pypi-internal
username: someuser
password: somepassword

Also, what's the difference between index and index-url in the pip.conf file?


Solution

  • .pypirc is a file standard used by multiple tools, but not by pip. For example, the easy_install tool reads that file, as does twine. It contains configuration on how to access specific PyPI index servers when publishing a package.

    pip.conf on the other hand is only used by the pip tool, and pip never publishes packages, it downloads packages from them. As such, it never looks at the .pypirc file.

    If you are not publishing packages, you don't need a .pypirc file. You can't use it to configure index servers for pip.

    As for the --index-url and --index switches, these are used for different pip commands.

    • --index-url is a common switch among several pip commands that deal with installing packages (pip install, pip download, pip list, and pip wheel), where it is part of a group of switches (together with --extra-index-url, --no-index, --find-links and --process-dependency-links and a few deprecated switches) that all together configure how package discovery works. The URL must point to a PEP 503 Simple Repository API location, the default is https://pypi.org/simple.

    • --index is only used by pip search; it only needs this one piece of information. It is named separately because it should point to the public search web interface, not the simple repository! For https://pypi.org, that's https://pypi.org/pypi.