How to setup two PyPI indices
pip installshould install/update packages from GitLab as well as PyPi repo. If same package is present in both, PyPi is preferred.
pip installshould support authentication. Preferred, if somehow we can make it read from a config file so that we don't need to specify it repeatatively.
--extra-index-urlto specify additional PyPi indexes. The same can also be provided via
~/.netrcas config file (docs).
- Create a
pip.iniif on Windows) in any of the locations suggested by
pip config -v list.
- Add your GitLab PyPi index URL to
[install] extra-index-url = https://gitlab.com/api/v4/projects/12345678/packages/pypi/simple
- Create or update your
~/.netrcfile and add your auth details for GitLab.
machine gitlab.com login <token-name> password <token-pass>
- We can now install packages as simply as
pip install <package-name>.
pipwill now look at both indexes to find your packages, with preference provided to the one pointed by
- The same could have been possible for
pip searchtoo, had there been support for multiple indexes. Till then, one needs to manually specify which PyPi index URL should be used. GitLab does not seem to support
pip searchsince it throws 415 Client Error: Unsupported Media Type when specified as the PyPi index.
- As for your doubts, each section in
pip.confpoints to that particular command,
[install]provides configuration for
pip searchand so on.
[global]probably refers to parameters that can be specified for all the commands be it
.pypircfile is made specially for configuring package indexes related to upload (used by twine/flint), where as
pip.confis associated with configuring
pipwhich manages python packages on your local system.
Try this (based on information from https://github.com/pypa/pip/issues/6797 and Can pip.conf specify two index-url at the same time?):
[global] index-url = http://pypi.org/simple trusted-host = pypi.org gitlab.company.de extra-index-url= https://username:p[email protected]/api/v4/projects/2142423/packages/pypi