Python+SWIG+MinGW - setup.py builds the source and the pyd file, python "cannot find the module"
I'm using MinGW to build a PythonC module using Swig. When I tell Python to load the module, it fails and complains that Python cannot find the module.
The funny thing is that the module is in the same directory that I'm running Python in and the module is named _mod.pyd
. (I also have generated a mod.py
file that u开发者_JAVA技巧ses _mod.pyd
in the same path.)
It's frustrating like you wouldn't believe!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mod.py", line 25, in <module>
_mod = swig_import_helper()
File "mod.py", line 21, in swig_import_helper
_mod = imp.load_module('_mod', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
It builds cleanly (I'm using distutils) and all my dll's are located in a directory that has been exposed to PATH.
I'm on a Windows XP+MinGW platform (latest stable MinGW).
Thanks!
This is a common problem. You probably are using the binary version of Python for Windows which is compiled with MSC not with MinGW. You can see it looking what the interpreter says when you run it from command line. If it is the case you have two choices:
- compile the module with MSC or
- compile python interpreter with MinGW.
For the latter option, well, good luck. I have never been able to do it.
I ran across this article on the MinGW site under "How do I create Python extensions?"
http://www.mingw.org/wiki/FAQ
I knew there was a trick with pexports but, I've tested this out a couple of times with little/no success (that I can remember). Has anyone else been able to make that successfully work?
cheers,
ct
update
I also found this tutorial -> http://boodebr.org/main/python/build-windows-extensions And this tutorial -> http://www.mail-archive.com/modwsgi@googlegroups.com/msg04655.html
I think it could be as easy as running: "setup.py build -c mingw32"
Did you try:
python setup.py build --compiler=mingw32
?
精彩评论