1

I have a C extension for Python which I've been using on Linux for some time. Now I want to use it on a system running Windows 7 Pro and Python 3.4 (same as on Linux). The extension is part of a package, let's call it 'mypackage.myextension'. The whole package is installed using setup tools.

The package builds and installs without error, and the extension ends up in 'C:\Python34\lib\site-packages\mypackage\myextension.pyd' as expected.
But any attempt to import it fails with 'DLL load failed'. Adding the 'mypackage' directory to sys.path (directly, via PYTHONPATH or using a .pth file) doesn't help.

Now the strange thing is that when I create a setup.py that installs the extension on its own (not part of a package) so it ends up in site-packages directly, everything works fine.

This more or less eliminates the usual causes for the failure, so I'm sort of lost. Any hints ? TIA.

fadriaensen
  • 61
  • 1
  • 3
  • this could be a problem with 32bit vs 64bit but have you checked out http://stackoverflow.com/questions/19019720/importerror-dll-load-failed-1-is-not-a-valid-win32-application-but-the-dlls or http://stackoverflow.com/questions/14629818/importerror-dll-load-failed-1-is-not-a-valid-win32-application – Mike McMahon Nov 10 '14 at 20:01
  • What is the exact error? The failing process might be building a 32-bit DLL when you're using a 64-bit interpreter (or the other way around). – nobody Nov 10 '14 at 20:02
  • Sometimes, if the `ImportError` doesn't have any information, it's helpful to use [`ctypes`](https://docs.python.org/3/library/ctypes.html) to load the DLL directly. (You may still not understand what it says, but there may be information useful to others trying to diagnose it.) – abarnert Nov 10 '14 at 20:11

0 Answers0