Ask Your Question
0

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

asked 2014-04-25 22:55:08 -0600

miaca gravatar image

Traceback (most recent call last): I have followed the instructions on how to install it to use with python and I keep getting this error.

File "<pyshell#3>", line 1, in <module> import cv2 ImportError: DLL load failed: %1 is not a valid Win32 application.

edit retag flag offensive close merge delete

Comments

%1 was used as a file reference name in MSDos batch files. I am not sure what it would have in the python import file.

GrumbleLion gravatar imageGrumbleLion ( 2014-04-28 15:08:01 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-01-16 09:17:33 -0600

It has a very simple solution After installing opencv... you place cv2.pyd from C:\opencv\build\python\2.7\ x64 into C:\Python27\Lib\site-packages

instead, place cv2.pyd from C:\opencv\build\python\2.7\ x86 into C:\Python27\Lib\site-packages

edit flag offensive delete link more
0

answered 2017-11-07 11:55:52 -0600

lash81 gravatar image

updated 2017-11-07 11:56:59 -0600

Not a valid Win32 application means that the python shell is running 32 bits, but the opencv package cv2 that it is attempting to import is NOT 32 bits. Opencv only seems to provide an x64 or x86 option; they must not have updated their instructions or links after they updated their code.

To fix this, you need to install the 64 bit version of python, numpy, AND matplotlib. Unfortunately, this is a little trickier than one might expect because pip, the python package manager, is not included on python versions below 2.7.9, and the version OpenCV requires is 2.7.5. The other issue is that pip is meant to be run from a terminal and NOT the python IDLE console, because it is a module -- the console is equipped mainly for running individual lines of python code.

To acquire pip, you need to open a bash terminal. Bash is a system, reminiscent of command line interfaces wherein all programs had to be launched by typing a command (before GUIs came along), that can call other programs. The other problem is that Windows does not natively have Bash.

The solution: First, install the 64 bit version of Python 2.7.5 (MSI). Then install cygwin. Then type the following into the Cygwin terminal: C:/Python27/python.exe -m easy_install pip. This will install pip. Then you can type C:/Python27/python.exe -m pip numpy and C:/Python27/python.exe -m pip matplotlib. Then everything will be installed, and you can continue with the instructions here from step 3.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-25 22:55:08 -0600

Seen: 16,653 times

Last updated: Nov 07 '17