首页 > 解决方案 > 来自 setup.py 的 dh_python2 版本化依赖项

问题描述

我正在使用dpkg-buildpackage构建 python 模块的 .deb 包。在setup.py我已经指定install_requires=['othermodule>=2.0'] 但生成的控制文件没有指定版本。Depends: python (>= 2.7), othermodule, dh_python 正在根据 setup.py 文件猜测需求。但是dh_python2的联机帮助页指出

(默认忽略版本要求)

但我无法设法将版本包含在控制文件中。问题是没有包含的版本, .deb 包被安装,但随后启动我得到的程序:

pkg_resources.DistributionNotFound: The 'othermodule>=2.0' distribution was not found and is required by ...

因为安装的版本小于2.0

我希望能够只指定一次依赖版本(例如在 setup.py 中)

[编辑:]

我在 pydist.py 中看到函数 load() 在绝对路径中搜索:

def load(dname='/usr/share/python/dist/', fname='debian/pydist-overrides',
         fbname='/usr/share/python/dist_fallback'):

而不是在我的包结构所在的 ./debian 下。由于该软件包尚未安装(我正在构建它),因此找不到 pydist 文件。我错过了什么吗???

标签: pythonversionsetup.pydebinstall-requires

解决方案


Pybuild wiki中所述:

dh_python2 和 dh_python3 将正确填写安装依赖项(分别通过 ${python:Depends} 和 ${python3:Depends} )

因此,如果您将${python:Depends}在 debian/control 中使用,dh_python 将尝试将您的install_requiresfrom映射setup.py到实际的 deb 依赖项。像这样使用它:

Depends: python (>= 2.7), ${misc:Depends}, ${python:Depends}

您还可以othermodule像在 python 中一样为您的 debian/control 指定所需的版本:

Depends: python (>= 2.7), othermodule (>=2.0)

[编辑]

您可以pydist-overrides在 debian 文件夹下放置一个文件,PEP386用于强制 dh_python 在解析安装依赖项时包含版本信息。它使用与 .pydist 文件相同的语法:

OthermoduleName python-othermodule; PEP386

希望这可以帮助。


推荐阅读