项目场景:
项目是需要在内网不联网环境部署GitHub上一个有关音频、视频处理的深度学习Python工程,因此许多包需要下载好wheel包或tar包后在内网环境安装。
这个过程遇到了许多兼容性问题引起的报错。Python版本与librosa、numba、llvmlite版本兼容问题报错,系统未安装ffmpeg报错,以及安装ffmpeg过程报错。
GitHub项目是基于Python3.6的,环境需求如下:
librosa==0.7.0
numpy==1.17.1
opencv-contrib-python>=4.2.0.34
opencv-python==4.1.0.25
torch==1.1.0
torchvision==0.3.0
tqdm==4.45.0
numba==0.48
系统需要安装ffmpeg:
sudo apt-get install ffmpeg
(注:如果外网有条件,打Docker镜像的方式比离线一个个安装包更方便)
问题描述
本人尝试匹配了许多版本,其中numba与llvmlite版本依赖性比较强,基本上是一一对应的,尝试过程中匹配了很多包,过程艰辛。
接下来一一介绍遇到的报错问题和解决方案。
解决报错 ModuleNotFoundError: No module named ‘numba.decorators’
安装高版本的numba,如0.57.0版本的numba,会出现如上报错,可以卸载numba后,安装指定numba是0.48.0版本,注意,此时对应的llvmlite的版本是0.31.0(install numba的时候会提示Collecting llvmlite<0.32.0,>=0.31.0dev0 (from numba==0.48.0)
)。
解决方案一:
pip uninstall numba
pip install numba==0.48.0
此方案适用于Python3.6、3.7、3.8
如果有指定版本不存在也会出现如下报错:
ERROR: Ignored the following versions that require a different python version: 0.52.0 Requires-Python >=3.6,<3.9; 0.52.0rc3 Requires-Python >=3.6,<3.9; 0.53.0 Requires-Python >=3.6,<3.10; 0.53.0rc1.post1 Requires-Python >=3.6,<3.10; 0.53.0rc2 Requires-Python >=3.6,<3.10; 0.53.0rc3 Requires-Python >=3.6,<3.10; 0.53.1 Requires-Python >=3.6,<3.10; 0.54.0 Requires-Python >=3.7,<3.10; 0.54.0rc2 Requires-Python >=3.7,<3.10; 0.54.0rc3 Requires-Python >=3.7,<3.10; 0.54.1 Requires-Python >=3.7,<3.10
ERROR: Could not find a version that satisfies the requirement numba==0.53.0 (from versions: 0.1, 0.2, 0.3, 0.5.0, 0.6.0, 0.7.0, 0.7.1, 0.7.2, 0.8.0, 0.8.1, 0.9.0, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.12.1, 0.12.2, 0.13.0, 0.13.2, 0.13.3, 0.13.4, 0.14.0, 0.15.1, 0.16.0, 0.17.0, 0.18.1, 0.18.2, 0.19.1, 0.19.2, 0.20.0, 0.21.0, 0.22.0, 0.22.1, 0.23.0, 0.23.1, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.1, 0.29.0, 0.30.0, 0.30.1, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.1, 0.36.2, 0.37.0, 0.38.0, 0.38.1, 0.39.0, 0.40.0, 0.40.1, 0.41.0, 0.42.0, 0.42.1, 0.43.0, 0.43.1, 0.44.0, 0.44.1, 0.45.0, 0.45.1, 0.46.0, 0.47.0, 0.48.0, 0.49.0, 0.49.1rc1, 0.49.1, 0.50.0rc1, 0.50.0, 0.50.1, 0.51.0rc1, 0.51.0, 0.51.1, 0.51.2, 0.52.0rc2, 0.55.0rc1, 0.55.0, 0.55.1, 0.55.2, 0.56.0rc1, 0.56.0, 0.56.2, 0.56.3, 0.56.4, 0.57.0rc1, 0.57.0)
ERROR: No matching distribution found for numba==0.53.0
解决方案二:修改librosa的库中的decorators.py文件,注释掉相关部分。
当使用Python3.10时,下载的librosa版本为0.7.2,numba版本为0.57.0,对应的llvmlite版本为0.40.0,此时librosa对应的依赖包版本如下:
Requirement already satisfied: librosa in /usr/local/lib/python3.10/dist-packages (0.7.2)
Requirement already satisfied: audioread>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from librosa) (3.0.0)
Requirement already satisfied: decorator>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from librosa) (5.1.1)
Requirement already satisfied: joblib>=0.12 in /usr/local/lib/python3.10/dist-packages (from librosa) (1.2.0)
Requirement already satisfied: numba>=0.43.0 in /usr/local/lib/python3.10/dist-packages (from librosa) (0.57.0)
Requirement already satisfied: numpy>=1.15.0 in /usr/local/lib/python3.10/dist-packages (from librosa) (1.24.3)
Requirement already satisfied: resampy>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from librosa) (0.4.2)
Requirement already satisfied: scikit-learn!=0.19.0,>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from librosa) (1.2.2)
Requirement already satisfied: scipy>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from librosa) (1.10.1)
Requirement already satisfied: six>=1.3 in /usr/local/lib/python3.10/dist-packages (from librosa) (1.16.0)
Requirement already satisfied: soundfile>=0.9.0 in /usr/lib/python3/dist-packages (from librosa) (0.10.3.post1)
Requirement already satisfied: llvmlite<0.41,>=0.40.0dev0 in /usr/local/lib/python3.10/dist-packages (from numba>=0.43.0->librosa) (0.40.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn!=0.19.0,>=0.14.0->librosa) (3.1.0)
到librosa所在位置,可通过 pip install librosa
查看所在位置
我的安装位置在:
/usr/local/lib/python3.10/dist-packages
打开 /usr/local/lib/python3.10/dist-packages/librosa/util/decorators.py
将如下部分注释掉
import warnings
from decorator import decorator
import six
# 下面一行注释掉
# from numba.decorators import jit as optional_jit
# 下面一行去掉optional_jit
#__all__ = ['moved', 'deprecated', 'optional_jit']
__all__ = ['moved', 'deprecated']
再运行就没有如上报错了。参考:
No module named numba.decorators错误解决
解决Python报错AttributeError: module ‘llvmlite.binding.ffi’ has no attribute ‘register_lock_callback’
出现这种报错的情况是Python3.7运行程序,执行到 import numba
时报错:AttributeError: module ‘llvmlite.binding.ffi’ has no attribute ‘register_lock_callback’,原因是llvmlite的版本低于0.36.0,
解决方案一:安装0.36.0以上版本的llvmlite。
以下是Python3.7可行的安装包版本:
librosa==0.7.0
numba==0.53.0
llvmlite==0.36.0
这种方案,numba版本不是0.48.0了,可能会出现其他问题。
参考:运行python报错AttributeError: module ‘llvmlite.binding.ffi’ has no attribute ‘register_lock_callback’
解决方案二:借用0.36.0版本的llvmlite中的binding文件夹
当你想使用0.48.0版本的numba,而与之匹配的0.31.0版本的llvmlite没有llvmlite.binding.ffi,你可以先安装0.36.0版本的llvmlite,在你的site-packages路径中找到llvmlite文件夹,将里面的binding文件夹复制下来,卸载0.36.0版本的llvmlite,重新安装0.31.0版本的llvmlite,并将上面binding文件夹放入llvmlite文件夹中。
(此方法是在尝试中发现的,简单粗暴,不是很推荐使用)
解决import librosa报错问题
多是版本过低,如librosa版本是0.6.0版本的,推荐安装0.7.0或0.7.2以上版本的librosa。安装librosa需要先安装llvmlite,再安装numba,再安装librosa。