Sign in to follow this  
Basss

SWIG doesn't produce .py file

Recommended Posts

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

Share this post


Link to post
Share on other sites
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. :(

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this