问题
When I passed on win7 (python3)
pip install opencv-python
pip install opecncv-contrib-python
Can be correct import CV2
But when I installed opencv on window server 2008 R2 enterprise, this was the following error:
In [2]: import cv2
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-c8ec22b3e787> in <module>()
----> 1 import cv2
c:\python36\lib\site-packages\cv2\__init__.py in <module>()
1 import importlib
2
----> 3 from .cv2 import *
4 from .data import *
5
ImportError: DLL load failed: The specified module could not be found.
I tried installing C++
Redistributable Package (all versions) and downloading WHL files still can't solve the error.
C:\Users\Administrator\Desktop>ipython
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD6
4)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import cv2
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-c8ec22b3e787> in <module>()
----> 1 import cv2
ImportError: DLL load failed: The specified module could not be found.
My guess is definitely a system problem, but I checked the data and found that the prototype of the server 2008 R2 system is Win7, and I've installed what I can hold, and still can't solve the problem.
So I wanted to know what the real reason for this mistake was, and if I could figure it out and fix it.
So what should I do to ask for help
回答1:
This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.
Neither conda nor any other virtual manager running python natively on windows will solve this unless you install the feature pack. However WSLbash and VMWare will run cv2 without feature pack.
回答2:
Try first installing Anaconda, then install opencv with conda. For example opening Conda Prompt in windows and type conda install opencv
, instead of using pip
. That did the trick for me.
回答3:
If you are using python 3.6, it may be because of dependency error. Try installing old versions of opencv. For example python-3.6 may conflicts with opencv-4.0.1. Installing previous version(3.4.1) works fine in windows 7 system.
To uninstall old version
pip uninstall opencv-python
To install new version
pip install opencv-python==3.4.1.14
if it fails, find the corresponding version that matches.
来源:https://stackoverflow.com/questions/51760955/import-cv2-dll-load-failed