Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: DLL load failed: The specified procedure could not be found. Python

Recently, I have installed a current version of Python(x,y) package (2.7.6.0) and now when I run my python code, it shows an error:

Traceback (most recent call last):
File "D:\Projects\comparison\Lagebestimmung\main.py", line 11,   in <module>
import cv2
ImportError: DLL load failed: The specified procedure could not be found.

I correctly selected opencv module during the installation.

Also, I use to have an older version of Python(x,y) before in my computer which I uninstalled before installing the new version. In that version, there was no such problem.

like image 291
Sanchit Avatar asked Mar 06 '14 10:03

Sanchit


People also ask

How do you resolve Importerror dll load failed the specified module could not be found?

importerror: dll load failed: The specified module could not be found error occurs because of the incompatibilities of Microsoft Visual C++ (Visual Studio) versions. The best way to fix this error (importerror: dll load failed) is to reinstall/ install the Microsoft Visual C++ distribution.

How do I import a picture into PIL?

To load the image, we simply import the image module from the pillow and call the Image. open(), passing the image filename. Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL).


2 Answers

For programmers using python 3, download a wheel package in order to install OpenCV.

You will need to make sure that NumPy is already installed. Anaconda is a nice package to handle dependencies. You would get numpy out of the box with it.

Then, download the OpenCV version corresponding to your Python installation version from : http://www.lfd.uci.edu/~gohlke/pythonlibs/

You can find the version of your Python interpreter by running:

python --version

In my case as I run C-Python 3.5, I chose : opencv_python‑3.2.0‑cp35‑cp35m‑win_amd64.whl

Finally, in the directory you have downloaded the wheel package, run:

pip install opencv_python-3.X.X-cpXX-cpXXm-xxxx.whl
like image 80
djondal Avatar answered Oct 07 '22 06:10

djondal


  1. Use Dependency Walker (http://www.dependencywalker.com/) on your cv2.pyd from 'site-packages'.
  2. Look at the higher-left corner, where the library tree is.
  3. Normal libraries have blue or gray icons, find libraries with red icons on the left, like this: http://i.stack.imgur.com/YiEuD.png.
  4. Find API's having a red flag and remember parent library names of the libraries with red icon. Red flag means that parent library requires some API, which is absent in the underlying library. In my case a library with the red icon is 'kernel32.dll', and it's parent libraries are msvcr90.dll, tbb.dll and the library from 'winsxs', which name's is obscured.
  5. Usually a problem can be solved by obtaining correct versions of the parent libraries. For example, you are trying to use a DLL, which is compiled for Windows Vista, on Windows XP. This DLL imports a 'InitializeCriticalSectionEx' API, which is absent in Windows XP's 'kernel32.dll'. Obtaining the XP version of your DLL or recompiling it with 'InitializeCriticalSection' instead of 'Ex' will solve the problem. Another example: you are using OpenCV compiled for use with Qt 4.8.4 and PyQt4, which contains Qt version 4.7. cv2.pyd (which is a DLL, by the way) will refuse to import because certain Qt API's required in your OpenCV are not available in 4.7's DLL's. The solution is to put Qt libraries version 4.8.4 into your '%PYTHONHOME%\Lib\site-packages\PyQt4' folder or PATH. I encountered this problem myself when building my own version of OpenCV from git repo.
like image 35
ogurets Avatar answered Oct 07 '22 07:10

ogurets