Python 从专用PyPI定义setup.py依赖项

Python 从专用PyPI定义setup.py依赖项,python,setuptools,setup.py,pypi,Python,Setuptools,Setup.py,Pypi,我想通过在setup.py中指定依赖项,从我的私有PyPI安装依赖项 我已经尝试通过以下方式指定在dependency\u链接中查找依赖项的位置: setup( ... install_requires=["foo==1.0"], dependency_links=["https://my.private.pypi/"], ... ) 我还尝试在依赖项链接中定义整个URL: setup( ... install_requires=[],

我想通过在
setup.py
中指定依赖项,从我的私有PyPI安装依赖项

我已经尝试通过以下方式指定在
dependency\u链接中查找依赖项的位置:

setup(
    ...

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

    ...
)
我还尝试在
依赖项链接中定义整个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')
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)
而在第二种情况下,我没有得到任何错误,只有以下内容:

...

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
安装它,但仍然出现以下错误:

...

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

以下是输出:

...

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\u requires
中使用
foo==1.0


更新

请注意,pip目前不支持
依赖链接
(但一些较旧版本的pip支持)

对于pip,另一种选择是使用命令行选项,例如或。这些选项不能在项目用户身上强制执行(与setuptools中的依赖项链接相反),因此必须正确记录这些选项。为了促进这一点,一个好主意是为项目的用户提供。该文件可以包含一些pip选项,特别是可以按行(即按要求)指定这些选项

例如:

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

您遇到了什么错误?在第一种情况下,我找不到'foo'的索引页(可能拼写错误?),在第二种情况下,我没有收到任何错误/警告,只是查看了其他依赖项。您可以提供一些有关您的私有包索引的详细信息吗?你在使用一些特定的软件吗?或者,如果你自己构建了一些东西,那么目录树是什么样子的呢。我已经按照您的指示更新了问题。位“(来自版本:无)”令人担忧。这似乎意味着pip(或setuptools)无法找到任何版本的foo。您是否仔细检查过机器是否可以下载
.tar.gz
文件,例如使用curl或wget?另外,当要求更详细的输出时(pip安装--verbose/tmp/test/dist/test-1.0.0.tar.gz
),是否会出现任何相关信息?我可以通过curl或从浏览器直接下载库。我已经更新为使用
pip安装--verbose
Oh获得的输出来提问。。。但是,在从setuptools到pip的过程中,您会遇到一些问题。您最初的问题提到python setup.py安装,然后在更新中您开始提到pip安装。但是pip不支持依赖链接(一些旧版本支持)。能否使用python setup.py安装重试?对于pip来说,还有其他选择。对不起,是我的错,我一起做了两个不同的测试!使用
python setup.py安装
并遵循您的建议,它就可以工作了!现在,问题是我需要对pip做同样的事情,你能告诉我哪些是替代品吗?附言:我接受你的回答