Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv-python 3.0 with python 3.5 on windows

A long time ago I managed to get opencv-python 3 working with python 3.4 on windows (which was a struggle). I wrote a lot of good code, then lost my working file system. I simply cannot reproduce a working system with a new install of python 3.5 on windows. The sad moment is when I try to import cv2: ImportError: DLL load failed: The specified module could not be found.

Any help would really be hugely appreciated as I've been at this for way too long. Here are answers to the usual questions:

  • Microsoft Windows [Version 10.0.10240]
  • Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
  • pip shows that opencv-python (3.0.0) is installed
  • I installed it from the wheel on Gohlke's site: opencv_python‑3.0.0‑cp35‑none‑win32.whl
  • I have these entries in my PATH : C:\Python35\Scripts\; C:\Python35\; %OPENCV_DIR%\bin;
  • I have the environment variable: OPENCV_DIR = C:\opencv\build\x64\vc12\
    (and I've tried the variants with x86 and vc11)
  • from python, it can find the module:
>>> import imp
>>> imp.find_module('cv2')
(<_io.BufferedReader name='C:\\Python35\\lib\\site-packages\\cv2.cp35-win32.pyd'>, 'C:\\Python35\\lib\\site-packages\\cv2.cp35-win32.pyd', ('.cp35-win32.pyd', 'rb', 3))

I tried all the steps again on a second machine (all the same as above except Windows 8.1). Every other package I install works fine (numpy, matplotlib, flask, more). Same problem. How do I debug this? (Thank you for looking at this problem).

opencv-python 3.0 with python 3.5 on windows

A long time ago I managed to get opencv-python 3 working with python 3.4 on windows (which was a struggle). I wrote a lot of good code, then lost my working file system. I simply cannot reproduce a working system with a new install of python 3.5 on windows. The sad moment is when I try to import cv2: ImportError: DLL load failed: The specified module could not be found.

Any help would really be hugely appreciated as I've been at this for way too long. Here are answers to the usual questions:

  • Microsoft Windows [Version 10.0.10240]
  • Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
  • pip shows that opencv-python (3.0.0) is installed
  • I installed it from the wheel on Gohlke's site: opencv_python‑3.0.0‑cp35‑none‑win32.whl
  • I have these entries in my PATH : C:\Python35\Scripts\; C:\Python35\; %OPENCV_DIR%\bin;
  • I have the environment variable: OPENCV_DIR = C:\opencv\build\x64\vc12\
    (and I've tried the variants with x86 and vc11)
  • from python, it can find the module:
>>> import imp
>>> imp.find_module('cv2')
(<_io.BufferedReader name='C:\\Python35\\lib\\site-packages\\cv2.cp35-win32.pyd'>, 'C:\\Python35\\lib\\site-packages\\cv2.cp35-win32.pyd', ('.cp35-win32.pyd', 'rb', 3))

I tried all the steps again on a second machine (all the same as above except Windows 8.1). Every other package I install works fine (numpy, matplotlib, flask, more). Same problem. How do I debug this? (Thank you for looking at this problem).

Next day:

Phew! I got things working again. I'm adding these details in the hope that it will help someone else.

First, in answer to berak's question: Dependency Walker was giving me red -- cannot find file specified -- for the following modules (in this case, on my Win 8.1 laptop):

API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL
API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL
API-MS-WIN-CORE-SHUTDOWN-L1-1-1.DLL
EXT-MS-WIN-NTUSER-UICONTEXT-EXT-L1-1-0.DLL
IESHIMS.DLL

Chasing those down turned out to be a red herring. I spoke to a friend at work who warned me not to trust Dependency Walker's errors (as is does not always correctly mimic how newer Windows OS find a DLL). It seems other folks have also been led down the wrong path (try searching the web for "Dependency Walker is misleading").

Here's what worked for me (and if anyone is expert in DLL registration conflicts, please correct me):

I was previously using the opencv wheel (from the Gohlke site) that was built for Windows Python 3.4. The dependency was on Visual C++ 2010. These wheels don't include the VC++ Redistributable for the compiler that was used (I assume because of Microsoft licensing restriction). So, I had to separately download & install Microsoft Visual C++ 2010 Redistributable.

For the newer wheel, that was built for Windows Python 3.5, Gohlke site says the dependency is on Visual C++ 2015. So I had to download & install Microsoft Visual C++ 2015 Redistributable. Which I did.

This is the reasoning I'm fuzzy on: The VC++ 2010 redistributable was still on my system. If it had DLLs that were in use at the time the VC++ 2015 redistributable was installed (or if a VC++ 2010 file had a more recent date due to a patch?) then some portion of the registration of the VC++ 2015 redistributable would have failed (silently?).

To back this out, I uninstalled the 2015 package, then uninstalled the 2010 package, then re-installed the 2015 package. Then, the original error ImportError: DLL load failed: The specified module could not be found was resolved.

Aside: I think it was reasonable for berak to admonish me for using a 3rd party wheel. If I had been working on machines that already had C++ build tools present, I might have been more adventurous about building my own static library for opencv, instead of relying on dynamic linking to DLLs. That's what the opencv doc says to do. But that can be daunting. I have half a clue about Windows development but many people don't. They just want to install python, pip install some extensions, and go.

Also worth noting: If you do use the pre-built opencv-python wheel, you don't even need to install OpenCV separately. I verified this on my system by renaming the opencv directory, removing the OPENCV_DIR environment variable, and taking any reference to OPENCV_DIR out of my path. Opencv-python still works fine. The wheel for Python 3.5 puts all the opencv DLLs in the same directory as opencv-python. On my system, that is:

C:\Python35\Lib\site-packages:

opencv_calib3d300.dll
opencv_core300.dll
opencv_features2d300.dll
opencv_ffmpeg300.dll
opencv_flann300.dll
opencv_highgui300.dll
opencv_imgcodecs300.dll
opencv_imgproc300.dll
opencv_ml300.dll
opencv_objdetect300.dll
opencv_photo300.dll
opencv_python-3.0.0.dist-info
opencv_shape300.dll
opencv_stitching300.dll
opencv_superres300.dll
opencv_video300.dll
opencv_videoio300.dll
opencv_videostab300.dll