【发布时间】:2021-06-28 15:32:26
【问题描述】:
我无法构建依赖于私有 PyPI 存储库(托管在 Sonatype Nexus Repository Manager,vOSS 3.17.0-01 上)中的包的 python 轮。
如果我使用pip,我可以搜索并安装该软件包;我的问题是试图让setup.py 做同样的事情。通过查看各种命令的输出,我认为问题可能是由于存储库提供的包链接中的相对路径。
搜索类似问题,大多涉及私有git 仓库。我能找到的最相关的相关问题是Equivalent for `--find-links` in `setup.py`。该评论的正文指出
在 setuptools 上下文中,
dependency_links选项接受...包含直接下载链接的网页的 URL
但是,为支持该引用而提供的链接页面不再包含该文本(已替换为较新的版本?)
所以这可能是问题所在 - 我尝试做事的方式不受支持。如果是这样,有人可以提出一种可行的方法吗?
另外,这可能是 setuptools 中的错误,或者是我们的 Nexus 的错误配置问题 - 如果有人可以证实或反驳这些理论 - 再次提出可行的方法 - 我将不胜感激。
这是我的设置和各种命令的输出,显示了哪些有效,哪些无效:
-
设置环境:
mkdir depends-fail cd depends-fail python3 -m venv venv source activate venv/bin/activate pip install --upgrade pip pip install wheel # So we can use bdist_wheel build option. -
确认我们当前的 pip 版本:
(venv) $ pip --version pip 21.0.1 from /tmp/depends-fail/venv/lib/python3.6/site-packages/pip (python 3.6) -
确认 setuptools 版本:
(venv) $ python -c "import setuptools as s; print(s.version.__version__)" 39.0.1 -
在
depends-fail目录中,创建这个最小的setup.py文件,它将演示问题:from setuptools import setup setup( name='failed-dependencies', install_requires=['data-feed-ping>=0.5'], dependency_links=[ 'http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping', ] ) -
确认我们的依赖项在我们的私有存储库中可用:
(venv) $ pip search --trusted-host nexus.example.local \ > -i http://nexus.example.local/nexus/repository/pypi-playground-public/pypi \ > data-feed-ping响应确认包在本地可用:
⋮ Starting new HTTP connection (1): nexus.example.local:80 http://nexus.example.local:80 "POST /nexus/repository/pypi-playground-public/pypi HTTP/1.1" 200 239 data-feed-ping (0.5) - Determine response times of data feeds. -
当我们尝试构建和测试我们的最小包时会发生以下情况(这是触发依赖项下载的测试选项):
(venv) $ python setup.py bdist_wheel test包构建没有问题 - 但找不到依赖项:
running bdist_wheel running build ⋮ removing build/bdist.linux-x86_64/wheel running test Searching for data-feed-ping>=0.5 (1) Reading http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping (2) Downloading http://nexus.example.local/nexus/repository/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336 error: Can't download http://nexus.example.local/nexus/repository/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336: \ 404 Repository not found -
(2) 中的下载链接和版本哈希来自在 (1) 处读取的索引 URL 的内容 - 所以让我们看看该文件是什么样的:
(venv) $ curl http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping<html lang="en"> <head><title>Links for data-feed-ping</title><meta name="api-version" value="2"/></head> <body><h1>Links for data-feed-ping</h1> ⋮ <!-- links to previous versions --> <a href="../../packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336" rel="internal">data_feed_ping-0.5-py3-none-any.whl</a><br/> </body> </html>
索引 URL 确实提供了所需版本的 data-feed-ping 包的链接,并且设置脚本正确地从该链接获取 md5 摘要(请参阅脚本输出中的 (2))。但是,安装脚本随后会尝试从无效 URL 下载文件。
在我看来,问题似乎是索引链接提供的相对路径。如果我们从索引 URL (1) 开始:
http://nexus.example.local/nexus/repository/pypi-playground-public/simple/data-feed-ping
并添加下载的相对路径:
../../packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336
我得到以下绝对路径:
http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336
我已经确认该绝对路径指向我想要的包:
(venv) $ wget http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl#md5=e7a9ee0be6cc77165d02e7022c04b336
--2021-04-01 16:44:18-- http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl
Resolving nexus.example.local (nexus.example.local)... 192.168.24.136
Connecting to nexus.example.local (nexus.example.local)|192.168.24.136|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19066 (19K) [application/zip]
Saving to: ‘data_feed_ping-0.5-py3-none-any.whl’
data_feed_ping-0.5-py3-none-any 100%[==========================================>] 18.62K --.-KB/s in 0s
2021-04-01 16:44:18 (76.3 MB/s) - ‘data_feed_ping-0.5-py3-none-any.whl’ saved [19066/19066]
如果我尝试直接下载包,使用pip,指定安装脚本使用的相同索引 URL,我也没有问题:
(venv) $ pip install --trusted-host nexus.example.local \
> --index-url http://nexus.example.local/nexus/repository/pypi-playground-public/simple \
> data-feed-ping
Looking in indexes: http://nexus.example.local/nexus/repository/pypi-playground-public/simple
Collecting data-feed-ping
Downloading http://nexus.example.local/nexus/repository/pypi-playground-public/packages/data-feed-ping/0.5/data_feed_ping-0.5-py3-none-any.whl (19 kB)
Requirement already satisfied: requests in ./venv/lib/python3.6/site-packages (from data-feed-ping) (2.25.1)
⋮
Installing collected packages: data-feed-ping
Successfully installed data-feed-ping-0.5
【问题讨论】:
-
您应该只使用
pip(或任何其他安装程序)来安装 Python 项目。例如,通过调用python setup.py install进行安装是一种不好的做法。因此,您可能应该删除setup.py的dependency_links参数,并指示您的用户使用正确的 pip 标志进行安装,就像您在问题末尾显示的那样。
标签: python-3.x pip nexus setuptools