>>> import cv2
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "
File "/home/face/anaconda3/envs/face/lib/python3.9/site-packages/cv2/__init__.py", line 5, in
from .cv2 import *
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "
File "/home/face/anaconda3/envs/face/lib/python3.9/site-packages/cv2/__init__.py", line 5, in
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
问题原因:numpy跟opencv版本不兼容,出现错误的版本是numpy==2.0.2,opencv==4.5.2.45
解决方法:降低numpy版本。输入命令:pip install numpy==1.23.2
成功解决