SWIG doesn't produce .py file

Started by
3 comments, last by Basss 13 years, 11 months ago
Hello, I've 2 c++ classes that I try to call from python by using swig. Now when I use "swig -c++ -python -classic myclass/myclass.i" and then compile all the cc files and the generated wrapper with "g++ -c -Wall -O4 -fPIC -I/usr/include/python2.6 *.cc myclass_wrap.cxx" and then link it with: "g++ -shared *.o -o _myclass.so" there is no .py file generated although it is necessary for importing the python module. The Internet tutorial doesn't seem to cover this. Does anybody know how to generate the .py file? Thanks, Basss
Advertisement
Have you tried renaming the .so file to .py? I haven't used python for a while but I think it loads native shared libraries directly.
No, that doesn't work unfortunately, in the .so file is no valid python code. In some examples they need both a .so and a .py file. But I only get the .so file. :(
I just tried compiling a sample extension that comes with Boost.Python. I put the .so file (without renaming) in the same directory as the python file and the extensions gets loaded and works fine. There is no extra file, just the .so file and the python source file that loads the module using import.
If the library is called 'ext.so' you can load it using 'import ext'. import can load both python files and shared libraries.
Do you get any error messages?
Yes, just using the .so file was the first thing I tried, but that got me the message that the module could not be found.

However, I just found the .py file, it was in the folder with my sources. For some reason, the .so file ends up in the folder where my executable is, while the .py ends up with the sources... Bit stupid that I didn't see that before.

Now I'm just left with a problem with a struct I use in my class, It can't find that struct when compiling the wrapper for that class (I provide it with the necessary object files). But I guess that is a totally different problem.

Thanks for your help so far!

This topic is closed to new replies.

Advertisement