Ubuntu20.04编译的Cython包无法在Debian9安装:平台不兼容求解
问题
在Ubuntu 20.04系统上编译了一个Cython化的Python包,使用Python 3.7.1、Cython 0.29.30,生成的包名为bbbox-2.0.6-cp37-cp37m-manylinux_2_31_x86_64.whl。该包可在其他Ubuntu 20.04服务器正常安装,但在Debian GNU/Linux 9 (stretch)系统上安装时,出现以下错误:
using pip 22.2 from /venvs/dztradeio_pre/lib/python3.7/site-packages/pip (python 3.7) Non-user install because user site-packages disabled Created temporary directory: /tmp/pip-ephem-wheel-cache-tu_4hz24 Created temporary directory: /tmp/pip-build-tracker-q85jg79w Initialized build tracking at /tmp/pip-build-tracker-q85jg79w Created build tracker: /tmp/pip-build-tracker-q85jg79w Entered build tracker: /tmp/pip-build-tracker-q85jg79w Created temporary directory: /tmp/pip-install-7_4efkhe ERROR:bbbox-2.0.6-cp37-cp37m-manylinux_2_31_x86_64.whl is not a supported wheel on this platform. Exception information: Traceback (most recent call last): File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper status = run_func(*args) File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper return func(self, options, args) File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 370, in run reqs, check_supported_wheels=not options.target_dir File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 73, in resolve collected = self.factory.collect_root_requirements(root_reqs) File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 493, in collect_root_requirements requested_extras=(), File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 452, in _make_requirement_from_install_req self._fail_if_link_is_unsupported_wheel(ireq.link) File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 138, in _fail_if_link_is_unsupported_wheel raise UnsupportedWheel(msg) pip._internal.exceptions.UnsupportedWheel:bbbox-2.0.6-cp37-cp37m-manylinux_2_31_x86_64.whl is not a supported wheel on this platform. Remote version of pip: 22.2 Local version of pip: 22.2 Was pip installed by pip? True Removed build tracker: '/tmp/pip-build-tracker-q85jg79w'
解决方案
原因分析
manylinux_2_31对应的是GLIBC 2.31版本,而Debian 9 (stretch)默认使用GLIBC 2.24,版本低于wheel要求的最低依赖,因此pip判定该wheel与当前平台不兼容。
具体解决办法
1. 降级pip并强制安装(临时应急方案)
pip 20.3及以后版本对manylinux标准的检查更严格,降级到旧版pip可绕过部分检查,再强制安装:
pip install pip==20.2.4 pip install bbox-2.0.6-cp37-cp37m-manylinux_2_31_x86_64.whl --force-reinstall --no-deps
注意:此方法可能引发运行时GLIBC版本不兼容报错(如version GLIBC_2.31 not found),若出现该情况需换用其他方案。
2. 在Debian 9环境重新编译包(推荐稳定方案)
直接在目标系统Debian 9上编译Cython包,生成适配GLIBC 2.24的wheel:
- 在Debian 9上安装Python 3.7.1、Cython 0.29.30及编译依赖(如
build-essential) - 进入包源码目录,执行编译命令:
python setup.py bdist_wheel
生成的wheel会自动适配当前系统的GLIBC版本,可正常安装运行。
3. 用manylinux_2_17标准重新编译(跨版本兼容方案)
若需生成兼容Debian 9及更高版本的wheel,可指定manylinux_2_17标准(对应GLIBC 2.17,Debian 9满足要求):
- 先编译出不带manylinux标签的
linux_x86_64wheel,再用auditwheel工具处理:
pip install auditwheel auditwheel repair bbox-2.0.6-cp37-cp37m-linux_x86_64.whl --plat manylinux_2_17_x86_64
也可直接在setup.py中配置编译时使用manylinux_2_17标准。
内容的提问来源于stack exchange,提问作者Wei Qiu
相关产品推荐
相关产品推荐

