Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 Windows 7 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 file in the Lib/site-packages folder of the Python interpreter.

Unfortunately, the suggestion of using the 32 bits version of Python isn't working for me any more as I have to handle NumPy arrays too large for 32 bits.


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

Everything seems to be working fine now!

like image 231
Francis Avatar asked Jan 31 '13 15:01

Francis


People also ask

What is 1 is not a valid Win32 application?

In most cases, the “1 is not a valid Win32 application” occurs due to the incompatibility between the Windows version/type and program. Please make sure you have downloaded the right version of the installer file. Press Windows key + R to call out the Run box.

How to fix “1 is not a valid Win32 application”?

Method 1. Download the Installer File Compatible with the System In most cases, the “1 is not a valid Win32 application” occurs due to the incompatibility between the Windows version/type and program. Please make sure you have downloaded the right version of the installer file. Press Windows key + R to call out the Run box.

What is [error 193] %1 is not a valid Win32 application?

[Error 193] %1 is not a valid Win32 application. DLL load failed: %1 is not a valid Win32 application. The specific error message may vary depending on what program you are opening or running, but there must be “%1 is not a valid Win32 application” in the error message. Why does the error occur? The possible reasons are as follows:

What are the most common import errors in Python?

python - ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL's are there - Stack Overflow ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL's are there

Why am I getting a DLL error when building shared libraries?

If your build system ( CMake in my case) copies the file from <name>.dll to <name>.pyd, you will get this error if the original file wasn't actually a DLL file. In my case, building shared libraries got switched off, so the underlying file was actually a *.lib.


2 Answers

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).

like image 117
Francis Avatar answered Sep 28 '22 04:09

Francis


You could try installing the 32 bit version of OpenCV.

like image 42
Oladapo Omonayajo Avatar answered Sep 28 '22 03:09

Oladapo Omonayajo