在导入cv2的时候报错,
(paddle) C:\Windows\system32>python
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\anaconda3\envs\paddle\lib\site-packages\cv2\__init__.py", line 8, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
>>> exit()
解决办法,
pip install -U numpy
产生的新问题,
(paddle) C:\Windows\system32>pip install -U numpy
Requirement already satisfied: numpy in d:\anaconda3\envs\paddle\lib\site-packages (1.19.3)
Collecting numpy
Downloading numpy-1.22.3-cp38-cp38-win_amd64.whl (14.7 MB)
|████████████████████████████████| 14.7 MB 547 kB/s
Installing collected packages: numpy
Attempting uninstall: numpy
Found existing installation: numpy 1.19.3
Uninstalling numpy-1.19.3:
Successfully uninstalled numpy-1.19.3
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
paddlepaddle-gpu 2.2.2 requires numpy<=1.19.3,>=1.13; python_version >= "3.5" and platform_system == "Windows", but you have numpy 1.22.3 which is incompatible.
openvino 2021.4.2 requires numpy<1.20,>=1.16.6, but you have numpy 1.22.3 which is incompatible.
openvino-dev 2021.4.2 requires numpy<1.20,>=1.16.6, but you have numpy 1.22.3 which is incompatible.
Successfully installed numpy-1.22.3
不过我测试了一下,这个新的ERROR目前还没有带来太大的问题。
为了满足兼容性,如果要改回版本,可以
pip install numpy==1.19.3
pip uninstall opencv-contrib-python
conda install opencv
注意,下面的指令会安装(卸载)最新版本的opencv,
pip (un)install opencv-contrib-python
本文结束
参考:
https://stackoverflow.com/questions/20518632/importerror-numpy-core-multiarray-failed-to-import