Alexander McFarlane
Alexander McFarlane

Reputation: 11293

The ImportError when importing 64bit dlls within 32bit python interpreter

The error code for importing a 32bit code in a 64bit python interpreter is

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

Is this the same error that is raised when importing 64bit code in a 32bit python interpreter?

If not, what is that error?

Upvotes: 1

Views: 1013

Answers (2)

ShadowRanger
ShadowRanger

Reputation: 155438

Update: I misread the original question (based on its use of the term "application" when it meant "extension module"). When you're talking about loading incompatible extension modules into Python, the error result should be the same; a 32 bit DLL (extension modules are just a minor special case of DLLs on Windows) is incompatible with a 64 bit Python executable, and a 64 bit DLL is incompatible with a 32 bit Python executable, for the same basic reason, and the error message (derived from the Windows error code returned when trying to dynamically load a DLL with incompatible bit-ness) would be the same.


Original answer about applications vs. modules preserved for posterity, but not relevant to the OP:


It's definitely not the same error; launching a 64 bit program isn't importing a module at all, so it wouldn't raise ImportError.

For that matter, as long as the OS is 64 bit and supports running a mix of 32 and 64 bit processes, 32 bit Python shouldn't experience a problem launching a 64 bit program; the problem is mixing and matching 32 and 64 bit code in the same process; two unrelated processes can have whatever bit-ness the OS/hardware support.

Upvotes: 1

Alexander McFarlane
Alexander McFarlane

Reputation: 11293

In Q&A style ... On a 64bit Windows Machine

  • Downloaded python directly from python.org in 32bit
  • Downloaded pyFFTW dlls for both 32bit and 64bit from gohlke/pythonlibs/ and the .pyd files

Running both imports...

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyfftw32
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
>>> import pyfftw64
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application.

Thus loading a 64bit application in a also gives the same ImportError

I also checked this with other 64bit .pyd binaries which gave a similar error.

Upvotes: 0

Related Questions