Install python package from private pypiserver

2020-07-10 09:34发布

问题:

I have setup a pypiserver behind an nginx proxy which uses htpasswd for authentication. I am currently able to upload sdists, but I can't figure out how to download them. I want to be able to download them when running setup.py test and somehow by using pip. Is this possible?

[distutils]
index-servers =
    private

[private]
repository = https://example.com/pypi
username = remco
password = mypass

To make it extra hard the server is currently using a non verified ssl connection.

I tried the following setup based on http://pythonhosted.org/setuptools/setuptools.html#setuptools-package-index, but the only documentation on this is 'XXX'

#!/usr/bin/env python2.7

from setuptools import setup


setup(
    name='asd',
    version='0.0.1',
    package_index='https://example.com/pypi/simple',
    test_suite='test',
    tests_require=['foo==0.0.1'])

回答1:

for using your index with pip create ~/.pip/pip.conf with this content:

[global]
index-url = https://remco:mypass@build.d-centralize.nl/pypi/simple
cert = /etc/ssl/certs/your_cert_CA.pem

A little bit documentation on pip.conf is here and on pypiserver here

Perhaps you can also try using package_index='https://user:pass@example.com/pypi/simple in setup.py.



回答2:

The server certificate had to be setup properly. For uploading using pip one must create a valid ~/.pypirc file:

[distutils]
index-servers = example

[example]
repository = https://example.com/pypi
username = myname
password = mypass

For installing packages one needs to add the following section to .pip/pip.conf

[global]
extra-index-url = https://myname:mypass@example.com/pypi/simple

As knitti noted in a previous answer it is also possible to user index-url instead of extra-index-url. This does mean that the cheese shop is not used as a second server.

For using a private server with setuptools unittesting you need to add the following to your setup.py:

from setuptools import setup

setup(
    ...
    dependency_links=[
        'https://myname:mypass@example.com/pypi/packages/'
    ])