使用setup.py和wheels安装软件包依赖项

时间:2014-09-09 14:57:14

标签: python pypi python-wheel devpi

我们正在使用内部托管的PyPI服务器(devpi-server),以便我们可以托管大量软件包的二进制轮,这些软件包需要很长时间才能从源代码安装,如scipy,matplotlib等。安装这些软件包与pip install scipy完美配合,绝对使用我们创造的轮子。但是,使用任何内部开发的python包,这些包依赖于其中一个包并运行python setup.py install|develop|test|whatever会导致以下错误:

No local packages or download links found for scipy
Traceback (most recent call last):
  File "setup.py", line 136, in <module>
    'develop': DevelopCommand
  File "/usr/local/lib/python2.7/distutils/core.py", line 112, in setup
    _setup_distribution = dist = klass(attrs)
  File "/users/me/virtualenvs/devpi-test/lib/python2.7/site-packages/setuptools/dist.py", line 239, in __init__
    self.fetch_build_eggs(attrs.pop('setup_requires'))
  File "/users/me/virtualenvs/devpi-test/lib/python2.7/site-packages/setuptools/dist.py", line 263, in fetch_build_eggs
    parse_requirements(requires), installer=self.fetch_build_egg
  File "/users/me/virtualenvs/devpi-test/lib/python2.7/site-packages/pkg_resources.py", line 564, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "/users/me/virtualenvs/devpi-test/lib/python2.7/site-packages/pkg_resources.py", line 802, in best_match
    return self.obtain(req, installer) # try and download/install
  File "/users/me/virtualenvs/devpi-test/lib/python2.7/site-packages/pkg_resources.py", line 814, in obtain
    return installer(requirement)
  File "/users/me/virtualenvs/devpi-test/lib/python2.7/site-packages/setuptools/dist.py", line 313, in fetch_build_egg
    return cmd.easy_install(req)
  File "/users/me/virtualenvs/devpi-test/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 587, in easy_install
    raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('scipy')

使用easy_install

$ easy_install scipy
Searching for scipy
Reading http://pypi.internal.example.com/us/base/+simple/scipy/
No local packages or download links found for scipy
error: Could not find suitable distribution for Requirement.parse('scipy')

如果我抓住了网址,我会看到:

$ curl http://pypi.internal.example.com/us/base/+simple/scipy/
<html>
  <head>
    <title>us/base: links for scipy</title></head>
  <body>
    <h1>us/base: links for scipy</h1>

    <form action="http://pypi.internal.example.com/us/base/+simple/scipy/refresh" method="post"><input name="refresh" type="submit" value="Refresh PyPI links"/></form>
us/external <a href="../../../external/+f/c48/5006bc28a8607/scipy-0.14.0-cp27-none-linux_x86_64.whl#md5=c485006bc28a8607b2fc1331df452dc1">scipy-0.14.0-cp27-none-linux_x86_64.whl</a><br/>
</body></html>

如果我请求该输出中列出的URL,我会得到方向盘:

$ curl --silent 'http://pypi.internal.example.com/us/external/+f/c48/5006bc28a8607/scipy-0.14.0-cp27-none-linux_x86_64.whl#md5=c485006bc28a8607b2fc1331df452dc1' \
      | file -
/dev/stdin: Zip archive data, at least v2.0 to extract

1 个答案:

答案 0 :(得分:1)

首先,问题中描述的问题不依赖于使用devpi,并且可以使用任何PyPI服务器复制,包括pypi.org的主要回购。例如:

# setup.py
from setuptools import setup

setup(name='spam', install_requires=['vprof>0.37'])

(而不是vprof,您可以使用除轮子之外不运送任何东西的任何其他包裹)

测试它:

$ pip install --upgrade "setuptools<38.2.0"
...
Successfully installed setuptools-38.1.0

$ python setup.py install
running install
running bdist_egg
running egg_info
writing spam.egg-info/PKG-INFO
...
Processing dependencies for spam==0.0.0
Searching for vprof>0.37
Reading https://pypi.python.org/simple/vprof/
No local packages or working download links found for vprof>0.37
error: Could not find suitable distribution for 
Requirement.parse('vprof>0.37')

邦。当您将仅二进制包声明为构建依赖项时,情况会变得更糟:

setup(name='spam', setup_requires=['vprof>0.37'])

现在所有构建和打包命令也将失败,无法下载构建代码。

问题完全取决于使用的setuptools版本。 Since 26 Nov 2017 and version 38.2.0, setuptools supports fetching and installing wheel dependencies,如果您仍然遇到此问题:

升级setuptools

较新的操作系统版本应该已经发布了setuptools的最新版本。例如,Ubuntu 18.04默认为setuptools==39.0.1link)。如果您仍然安装了旧版setuptools,则大部分时间它都将由系统软件包管理器管理,因此您不应通过pip进行更新。您可以用户安装setuptools

的其他副本
$ pip install --user --upgrade "setuptools>=38.2.0"

或使用虚拟环境。