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

ala*_*uri 5 pip setuptools pypi setup.py python-packaging

我想通过在setup.py.

我已经尝试通过以下方式指定在哪里查找依赖项dependency_links

setup(
    ...

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

    ...
)
Run Code Online (Sandbox Code Playgroud)

我还尝试在以下位置定义整个 URL dependency_links

setup(
    ...

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

    ...
)
Run Code Online (Sandbox Code Playgroud)

但是当我尝试安装时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')
Run Code Online (Sandbox Code Playgroud)

而在第二种情况下,我没有收到任何错误,只是出现以下错误:

...

Installed .../test-1.0.0-py3.7.egg
Processing dependencies for test==1.0.0
Finished processing dependencies for test==1.0.0
Run Code Online (Sandbox Code Playgroud)

更新1:

我尝试更改setup.py以下sinoroc的说明。现在我的setup.py样子是这样的:

setup(
    ...

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

    ...
)
Run Code Online (Sandbox Code Playgroud)

我使用 构建了库testpython 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)
Run Code Online (Sandbox Code Playgroud)

关于私有 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):

...
Run Code Online (Sandbox Code Playgroud)

sin*_*roc 2

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


更新

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

对于 pip,另一种方法是使用命令行选项,例如--index-url--extra-index-url--find-links。这些选项无法对项目的用户强制执行(与setuptools依赖项链接相反),因此必须正确记录它们。为了促进这一点,一个好主意是向项目的用户提供一个requirements.txt文件的示例。该文件可以包含一些 pip 选项。

例如:

# requirements.txt
# ...
--find-links 'https://my.private.pypi/'
foo==1.0
# ...
Run Code Online (Sandbox Code Playgroud)