ImportError: DLL load failed: %1 is not a valid Win32 application

Francis picture Francis · Jan 31, 2013 · Viewed 106.4k times · Source

I have this issue where I try to import cv2 on python and get the following error message.

>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application.

I do understand there are many posts about this where it is suggested that the bitness of the package is different from the python package.

However, everything I am running is 64 bits. I am on win7 64 bits, I have the winpython 2.7.3.3, 64 bits distribution, and I compiled opencv in 64 bits with the instruction provided here and placed the cv2.pyd dll in the Lib/site-packages folder of python.

Unfortunately the suggestion of using the 32 bits version of python isn't working for me anymore as I have to handle numpy arrays too large for 32 bits.

Thanks!!!

------ UPDATE

The only thing missing was to add the new opencv binaries path (C:\opencv\build\bin\Release) to the Windows PATH environment variable, restart python.

Everything seems to be working fine now!

Answer

Francis picture Francis · Jul 23, 2013

The ImportError message is a bit misleading because of the reference to Win32, whereas the problem was simply the opencv DLLs were not found.

This problem was solved by adding the path the opencv binaries to the Windows PATH environment variable (as an example, on my computer this path is : C:\opencv\build\bin\Release).