简体   繁体   中英

python failed to load 64 bit DLL on a 64 bit Windows

I wa testing a small python program that called underlying DLL libs.

My system is 64bit windows 7. The python executable is the one shipped with 64 bit Anaconda3, kicked off inside Anaconda's virtual environment.

First thing came to my attention is that this python code

sys.platform

return win32 even for a AMD64 Arch, "platform.machine()" seemed returning a more accurate result.

Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] on win32

I did find some SO posts discussing this issue, such as this one .

and then the program failed when trying to load a DLL file:

windll.LoadLibrary(realpath(join(_module_location, 'dlh', 'win64', 'I_cant_tell_you_the_name.dll')))

Error message:

OSError: [WinError 193] %1 is not a valid Win32 application

Question is, why python can't load a 64 bit DLL in a 64 bit environment? it seemed to me the compiler insisted on loading a 32 bit DLL instead. Why is that? Or that the venv that Anaconda created support only 32 bit code?

Unfortunately I didn't have a 32 bit DLL for testing, otherwise I'd like to see how that went.

You can use Dependency Walker to check what's happening. It has a profiling feature that will trace all library loads.

A few possible issues it can show you:

  1. Python is 32-bit because the wrong version was executed
  2. The DLL is 32-bit somehow
  3. The DLL depends on other DLLs that are not in the path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM