Define setup.py dependencies from a private PyPI

ぃ、小莉子 提交于 2020-01-24 08:50:07

问题


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):

...

回答1:


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 (i.e. per requirement).

For example:

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


来源:https://stackoverflow.com/questions/58695802/define-setup-py-dependencies-from-a-private-pypi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!