问题描述
在 import cv2 时出现以下报错
RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000
Traceback (most recent call last):
File "/xxx/mxxx.py", line 2, in <module>
import cv2
File "/xxx/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/xxx/miniconda3/envs/swinir/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/hxxx/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: numpy.core.multiarray failed to import
解决方案
- 搞清楚 cv2、numpy 以及 python 的版本
pip show opencv-python
,pip show numpy
,python --version
- 各种版本对应
- opencv-python 和 python 的版本对应参考:https://blog.csdn.net/m0_56312629/article/details/134830925
- numpy 和 python 的版本对应参考:https://blog.csdn.net/weixin_44458958/article/details/129665131
本文最终解决问题时的版本为:
- python:
3.10
- cv2:
opencv-python 4.6.0.66
- numpy:
1.22.2