从私有PyPI定义setup.py的依赖关系

5
我想通过在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"],

    ...
)

我使用 python setup.py sdist 命令构建了库 test,然后尝试使用 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,似乎只有一个位置可以查找库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):

...

你收到了什么错误? - Mad Physicist
在第一种情况下,我得到了“找不到'foo'的索引页面(可能拼写错误?)”,而在第二种情况下,我没有收到任何错误/警告,只是通过了其他依赖项。 - alauri
你能提供一些关于你的私有包索引的细节吗?你使用了特定的软件吗?或者如果是你自己构建的,目录树是什么样子的? - sinoroc
1个回答

2

在您的第二次尝试中,我认为您仍应该在install_requires中保留foo==1.0


更新

请注意,pip不支持dependency_links(曾经支持,但现在不再支持)。

对于pip,替代方法是使用命令行选项,例如--index-url--extra-index-url--find-links。这些选项不能强制用户使用您项目的人使用(与来自setuptoolsdependency links相反),因此必须进行适当的文档编写。为了方便,一个好主意是向您项目的用户提供requirements.txt文件的示例。此文件可以包含pip选项的一些内容。

例如:

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

您好sinoroc,感谢您的回复。我已经按照您的指示更新了问题。 - alauri
"(from versions: none)" 这一位似乎有些令人担忧。它似乎意味着 _pip_(或 _setuptools_)无法找到 foo 的任何版本。您是否已经确认机器实际上可以下载 .tar.gz 文件,例如使用 curl 或 _wget_?此外,在请求更详细的输出时(pip install --verbose /tmp/test/dist/test-1.0.0.tar.gz),是否有任何相关信息出现? - sinoroc
我可以直接通过curl或浏览器下载库。我已经使用pip install --verbose更新了问题并附上了输出。 - alauri
1
哦...但是在某个地方,你从_setuptools_转向了_pip_。你最初的问题提到了_python setup.py install_,然后在更新中开始提到_pip install_。但是_pip不支持_dependency_links_(一些旧版本支持)。你能否再试一次_python setup.py install_?对于_pip,有替代方案。 - sinoroc
1
抱歉,是我的错误,我把两个不同的测试合在了一起!使用“python setup.py install”并遵循您的建议,它现在可以工作了!现在,问题是我需要用pip来完成同样的操作,您能告诉我有哪些替代方案吗?PS:我会接受您的答案。 - alauri

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接