Error loading DLL in python, not a valid win32 application
As the comments suggest, it could be an architecture problem.
If you're using a 32bit DLL with 64bit Python, or vice-versa, then you'll probably get errors.
Since I've had your error before, I recommend trying to load your DLL with 32bit Python.
One way to test if a *.dll-file is 32bit or 64bit, is to use dumpbin.exe
, e.g.
dumpbin /headers dsusb.dll
...
FILE HEADER VALUES
14C machine (x86)
...
machine (x86)
means 32bit, machine (x64)
means 64bit.
ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL's are there
Unofficial Windows Binaries for Python Extension Packages
You can find any Python libraries from here.
ImportError: DLL load failed: %1 is not a valid Win32 application - scikit-learn+
I was able to fix it.
The way to go was 'force-reinstall'.
This was enough to get scikit-learn up and running.
pip install --upgrade --force-reinstall scipy
Ctypes throws WindowsError: [Error 193] %1 is not a valid Win32 application, but it's not a 32/64-bit issue
@eryksun commented:
Run under a debugger such as
cdb
orwindbg
. Callwindll.kernel32.DebugBreak()
just before callingCDLL(dllabspath)
. Set a breakpoint onkernelbase!LoadLibraryExW
and resume the thread viag
. When it breaks back into the debugger enterpt
to execute up to the function return. Then enter!teb
to check theLastStatusValue
for the thread. This NT status value may be of more help.
Further:
If you prefer to keep the system as clean as possible, try the following:
windll.kernelbase.LoadLibraryExW(c_wchar_p(dllabspath), None, 0); status = windll.ntdll.RtlGetLastNtStatus().
Otherwise it requires installing the debugging tools from the SDK. Symbols can be downloaded on demand from Microsoft's symbol server by setting the environment variable
_NT_SYMBOL_PATH=symsrv*symsrv.dll*C:\Symbols*http://msdl.microsoft.com/download/symbols
, which caches symbols inC:\Symbols
When debugging, this may help:
There are several status codes that produce Win32 error
ERROR_BAD_EXE_FORMAT
(193). In your case it'sSTATUS_INVALID_IMAGE_FORMAT
(0xC000007B
). Possibly in the production VM one of the dependent DLLs that it tries to load is 64-bit. At the breakpoint enterdu poi(@esp+4)
to print the first argument, which is the unicode path of the DLL it's attempting to load. Also check the stack trace viakc
.
Using this hint, I found a dependency on a 64-Bit WinPCAP DLL. Going through everything with DependencyWalker, it looked the same on both machines, complaining about a 64-Bit dependency, but apparently on the fresh machine, the DLL load path was different and it could never find the 32-Bit version.
Related Topics
Why Does @Foo.Setter in Python Not Work for Me
How to Integrate Flask & Scrapy
How to Schedule a Function to Run Every Hour on Flask
How to Get Current Function into a Variable
Reload Flask App When Template File Changes
Using Django Database Layer Outside of Django
How to Set "Camera Position" for 3D Plots Using Python/Matplotlib
How to Loop Through a List by Twos
How to Find Tags with Only Certain Attributes - Beautifulsoup
Which Seeds Have to Be Set Where to Realize 100% Reproducibility of Training Results in Tensorflow
Finding Elements Not in a List
How to Add Hours to Current Time in Python