简体   繁体   中英

Define setup.py dependencies from a private PyPI

I'd like to install dependencies from my private PyPI by specifying them within a setup.py .

I've already tried to specify where to find dependencies within the dependency_links this way:

setup(
    ...

    install_requires=["foo==1.0"],
    dependency_links=["https://my.private.pypi/"],

    ...
)

I've also tried to define the entire URL within the dependency_links :

setup(
    ...

    install_requires=[],
    dependency_links=["https://my.private.pypi/foo/foo-1.0.tar.gz"],

    ...
)

but when I try to install with python setup.py install , neither of them worked for me.

Can anybody help me?

EDITS:

With the first piece of code I got this error:

...

Installed .../test-1.0.0-py3.7.egg
Processing dependencies for test==1.0.0
Searching for foo==1.0
Reading https://my.private.pypi/
Reading https://pypi.org/simple/foo/
Couldn't find index page for 'foo' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
No local packages or working download links found for foo==1.0
error: Could not find suitable distribution for Requirement.parse('foo==1.0')

while in the second case I didn't get any error, just the following:

...

Installed .../test-1.0.0-py3.7.egg
Processing dependencies for test==1.0.0
Finished processing dependencies for test==1.0.0

UPDATE 1:

I've tried to change the setup.py following sinoroc's instructions. Now my setup.py looks like this:

setup(
    ...

    install_requires=["foo==1.0"],
    dependency_links=["https://username:password@my.private.pypi/folder/foo/foo-1.0.tar.gz"],

    ...
)

I built the library test with python setup.py sdist and tried to install it with pip install /tmp/test/dist/test-1.0.0.tar.gz , but I still get this error:

Processing /tmp/test/dist/test-1.0.0.tar.gz
ERROR: Could not find a version that satisfies the requirement foo==1.0 (from test==1.0.0) (from versions: none)
ERROR: No matching distribution found for foo==1.0 (from test==1.0.0)

Regarding the private PyPi, I don't have any additional information because I'm not the administrator of it. As you can see, I just have the credentials ( username and password ) for that server.

Additionally, that PyPi is organised in sub-folders, https://my.private.pypi/folder/.. where the dependency I want to install is.

UPDATE 2:

By running pip install --verbose /tmp/test/dist/test-1.0.0.tar.gz , it seams there is only 1 location where to search for the library foo , in the public server https://pypi.org/simple/foo/ and not in our private server https://my.private.pypi/folder/foo/ .

Here the output:

...

1 location(s) to search for versions of foo:
* https://pypi.org/simple/foo/
Getting page https://pypi.org/simple/foo/
Found index url https://pypi.org/simple
Looking up "https://pypi.org/simple/foo/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/foo/ HTTP/1.1" 404 13
Status code 404 not in (200, 203, 300, 301)
Could not fetch URL https://pypi.org/simple/foo/: 404 Client Error: Not Found for url: https://pypi.org/simple/foo/ - skipping
Given no hashes to check 0 links for project 'foo': discarding no candidates
ERROR: Could not find a version that satisfies the requirement foo==1.0 (from test==1.0.0) (from versions: none)
Cleaning up...
  Removing source in /private/var/...
Removed build tracker '/private/var/...'
ERROR: No matching distribution found for foo==1.0 (from test==1.0.0)
Exception information:
Traceback (most recent call last):

...

In your second attempt, I believe you should still have foo==1.0 in the install_requires .


Update

Be aware that pip does not currently support dependency_links (some older versions of pip did though).

For pip, the alternative is to use command line options such as --extra-index-url or --find-links . These options can not be enforced on the user of your project (contrary to the dependency links from setuptools ), so they have to be properly documented. To facilitate this, a good idea is to provide a requirements.txt file to the users of your project. This file can contain some of pip options, and in particular they can be specified per line (ie per requirement).

For example:

# requirements.txt
# ...
foo==1.0 --find-links 'https://my.private.pypi/'
# ...

You didn't specify the pip version you used, but support for dependency_links has been dropped by pip starting with version 19.0.

As long as your private package name doesn't conflict with an existing package name (it seems like it does not) you can just include it as a regular dependency:

install_requires=["foo==1.0"],

And when installing with pip , specify your private index via --extra-index-url :

$ pip install your_package --extra-index-url https://my.private.pypi/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM