10

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.

2
  • you copied cv2.pyd into site-packages directory ?? Mar 6, 2014 at 10:20
  • @PriyankPatel, Hi, No. I didn't. But can you please explain me what is it? Because I still remember the time when I installed an older version of Python(x,y) (which I already uninstalled). I did not need to configure or copy this 'cv2.pyd' into 'site-packages'. Thanks.
    – Sanchit
    Mar 6, 2014 at 10:26

5 Answers 5

11
  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: https://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.
2

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
1
  • Worked for Python 3.6 and OpenCV 3.3.0 with Anaconda3 (5.0.0)/Windows 10 After digging for 4 hours on SO and other websites, uninstalling everything and re-installing everything, this is the answer that made opencv work. Installing opencv from conda-forge with conda did not work for me even when trying to replace the file python3.dll as suggested in many question on SO.
    – Eskapp
    Oct 4, 2017 at 16:40
1

Try this: Install opencv for windows. download it at here :

http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.1/OpenCV-2.4.1.exe/download

Then

 Copy cv2.pyd from C:\opencv\build\python\x86\2.7\ and paste it in the folder python site-packages folder . restart your IDE. 

Make sure numpy is installed. If not , get it from here ..

http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
4
  • Hi, Thanks again for the help. But, as I told you, when you install Python(x,y) it asks about the modules/packages/components you would like to install. There you can select Opencv. I guess there is no need to install it again. Moreover, I checked site-packages and there exists already this file "cv2.pyd".
    – Sanchit
    Mar 6, 2014 at 11:06
  • 1
    dll errors can occur if you have installed python on 64 bits and the extension is compiled for 32 ...
    – StefanNch
    Mar 6, 2014 at 13:39
  • Hi, I solved the problem. I just installed another version (2.7.5.0) of Python(x,y): It works fine.
    – Sanchit
    Mar 6, 2014 at 15:22
  • Your answer does help people running python 3... The package still aims at people running python 2.
    – djondal
    Mar 10, 2017 at 14:54
0

I had the same problem and when i use ipython [just write ipython at cmd if you have ipython installed] it works.

0

the following worked for me. Assuming that Python(X,Y) is installed (and the option for OpenCV was checked at the beginning of the installation), I did the following steps:

  1. Download opencv-2.4.13, and extract file in a given folder.
  2. Copy file "cv2.pyd" (which is a file of 10MB)
  3. Replace the file cv2.pyd in the "...\Lib\site-packages" folder. You will notice that the original "cv2.pyc" file size is below 2MB.
  4. Start Python(x,y) and the Spyder. Type "cv2.version" in the Python console. You may get >>> cv2.version -> '2.4.13'
  5. OpenCV is now working!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.