cv2 import Error:
(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()
Solution:
pip install -U numpy
New problems,
(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
However, I tested it and found that this new error has not caused too many problems.
To meet compatibility, if you want to change back to the version, you can
pip install numpy==1.19.3
pip uninstall opencv-contrib-python
conda install opencv
Note that the following instructions will install (uninstall) the latest version of OpenCV,
pip (un)install opencv-contrib-python
Reference:
https://stackoverflow.com/questions/20518632/importerror-numpy-core-multiarray-failed-to-import