簡體   English   中英

使用setup.py和wheels安裝軟件包依賴項

[英]Install package dependencies with setup.py and wheels

我們正在使用一個內部托管的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')

如果我抓住了URL,我會看到:

$ 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

首先,問題中描述的問題不依賴於使用devpi ,可以使用任何PyPI服務器進行復制,包括pypi.org上的主要repo。 例:

# 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版本。 自2017年11月26日和版本38.2.0以來, setuptools支持獲取和安裝輪依賴項 ,因此如果您仍遇到此問題:

升級setuptools

較新的OS版本應該已經發布了最新版本的setuptools 例如,Ubuntu 18.04默認情況下具有setuptools==39.0.1鏈接 )。 如果您仍然安裝了舊的setuptools ,大多數時候它將由系統包管理器管理,因此您不應該通過pip更新它。 您可以用戶安裝setuptools的其他副本

$ pip install --user --upgrade "setuptools>=38.2.0"

或者使用虛擬環境。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM