从私有PyPI定义setup.py依赖项

我想通过在setup.py中指定私有pypI来安装依赖项。

我已经尝试通过以下方式指定在dependency_links中的依赖关系的查找位置:

setup(
    ...

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

我还尝试在dependency_links内定义整个URL:

setup(
    ...

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

但是当我尝试使用python setup.py install进行安装时,它们都不适合我。

有人可以帮助我吗?

编辑:

在第一段代码中,我遇到了这个错误:

...

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

在第二种情况下,我没有任何错误,只是以下内容:

...

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

更新1:

我已尝试按照sinoroc的指示更改setup.py。现在我的setup.py看起来像这样:

setup(
    ...

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

我用test构建了库python setup.py sdist,并试图用pip install /tmp/test/dist/test-1.0.0.tar.gz安装它,但是仍然出现此错误:

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)

关于私人pypi,我没有任何其他信息,因为我不是它的管理员。如您所见,我只有该服务器的凭据(用户名密码)。

此外,pypi是在子文件夹https://my.private.pypi/folder/..中组织的,我要安装的依赖项在其中。

更新2:

通过运行pip install --verbose /tmp/test/dist/test-1.0.0.tar.gz,它发现只有1个位置可以在公共服务器foo中而不是在我们的私有服务器https://pypi.org/simple/foo/中搜索库https://my.private.pypi/folder/foo/

在这里输出:

...

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

...
yanyantianlong 回答:从私有PyPI定义setup.py依赖项

第二次尝试,我相信您在foo==1.0中应该仍然有install_requires


更新

请注意, pip 当前不支持dependency_links(不过某些较早版本的pip可以支持)。

对于pip,替代方法是使用命令行选项,例如--extra-index-url--find-links。这些选项无法在您的项目用户上执行(与 setuptools 中的依赖项链接相反),因此必须对其进行正确记录。为此,一个好主意是向项目用户提供requirements.txt file。该文件可以包含一些pip选项,尤其是可以按行(即按要求)指定它们。

例如:

# requirements.txt
# ...
foo==1.0 --find-links 'https://my.private.pypi/'
# ...
本文链接:https://www.f2er.com/3165857.html

大家都在问