【问题标题】:Define setup.py dependencies from a private PyPI从私有 PyPI 定义 setup.py 依赖项
【发布时间】:2020-02-29 21:49:58
【问题描述】:

我想通过在 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,它会在公共服务器https://pypi.org/simple/foo/ 中而不是在我们的私人服务器https://my.private.pypi/folder/foo/ 中搜索库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):

...

【问题讨论】:

  • 你遇到了什么错误?
  • 在第一种情况下,我得到 Couldn't find index page for 'foo'(可能拼写错误?),在第二种情况下,我没有收到任何错误/警告, 简单地通过了其他依赖项
  • 你能提供一些关于你的私有包索引的细节吗?你在使用一些特定的软件吗?或者如果是你自己构建的东西,目录树是什么样子的?

标签: python setuptools setup.py pypi


【解决方案1】:

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


更新

请注意,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/'
# ...

【讨论】:

  • 您好 sinoroc,感谢您的回复。我已按照您的指示更新了问题。
  • (from versions: none)”这一点令人担忧。这似乎暗示 pip(或 setuptools)无法找到任何版本的 foo。您是否仔细检查过机器是否可以实际下载 .tar.gz 文件,例如使用 curlwget ?在要求更详细的输出 (pip install --verbose /tmp/test/dist/test-1.0.0.tar.gz) 时是否还会出现任何相关内容?
  • 我可以通过 curl 或浏览器直接下载该库。我已经更新了pip install --verbose 的输出问题
  • 哦...但是在从 setuptoolspip 的过程中。您最初的问题提到了 python setup.py install,然后在您的更新中您开始提到 pip install。但是 pip 不支持 dependency_links (一些旧版本支持)。你能用 python setup.py install 再试一次吗?对于 pip 有其他选择。
  • 对不起,我的错,我一起做两个不同的测试!使用python setup.py install 并按照您的建议进行操作!现在,问题是我需要对 pip 做同样的事情,你能告诉我哪些是它的替代品吗? PS:我会接受你的回答
猜你喜欢
  • 2012-05-21
  • 2015-01-10
  • 1970-01-01
  • 2018-12-17
  • 2014-07-21
  • 2020-03-08
  • 1970-01-01
  • 1970-01-01
  • 2012-12-18
相关资源
最近更新 更多