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

Define setup.py dependencies from a private PyPI

我想通过在 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,它发现在 public 服务器 https://pypi.org/simple/foo/ 中只有 1 个位置可以搜索库 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):

...

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


更新

请注意,pip 目前不支持 dependency_links(尽管一些旧版本的 pip 支持)。

对于 pip,另一种方法是对项目的用户使用命令行选项,例如 --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。该文件可以包含一些 pip 选项,特别是它们可以按行指定(即按要求)。

例如:

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