DLL Load Failed: %1 is not a valid win32 application

12.8k views Asked by At

So I have a situation where I need to make binary patches and then be able to apply them from within python. I found bsdiff which looks like a great algorithm and has a python extension module, but that extension module doesn't have a windows installer past Python 2.5

Alright, so having never even written C seriously, let alone attempted a python extension module, I set out to compile it myself. After a few hours of bashing my head against a DLL load error with MinGW32, I managed to get it compiled and built using the setup.py provided in the source of the project. However, upon importing the resulting bsdiff module, I get:

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

I'm running 64 bit python.

Any advice?

1

There are 1 answers

0
ldiary On

It's a mismatch in versions of Python and pywin32. I got the same error message after installing pywin32 in a virtual environment using easy_install: (py351env) C:\Users\ernesto.luzon\Downloads>easy_install pywin32-220.win-amd64-py3.5.exe

When I tried to import win32gui I got exactly the same error: DLL Load Failed: %1 is not a valid win32 application

Googling for the error message led me to this post where cgohlke suggested to download the pywin32 package from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32

I downloaded the 64bit version and installed it via pip: pip install pywin32-220-cp35-none-win_amd64.whl

Right away I got an error message that my python version does not match with the package I was trying to install. So I typed 'python' in my command line to launch the interpreter, and indeed the python installed in my 64bit machine was a 32bit python. After uninstalling python and correctly installing the 64bit one, this error disappeared, whether I use easy_install to install pywin32 from the sourceforge project, or I use pip to install the wheel file from gohlke.