views:

89

answers:

2

Hello,

I've a problem with SWIG and python. I've a c-class that compiles correctly, but the python script says it can't find the module.

I compile with:

swig -c++ -python codes/codes.i
g++ -c -Wall -O4 -fPIC -pedantic codes/*.cc
g++ -I/usr/include/python2.6 -shared codes/codes_wrap.cxx *.o -o _codes.so

This gives me a _codes.so file, as I would expect, but then I have this python file:

import sys
import codes

(rest of the code omitted)

It gives me:

 Traceback (most recent call last):
   File "script.py", line 3, in <module>
    import codes
ImportError: No module named codes

According to http://www.swig.org/Doc1.3/Introduction.html#Introduction_nn8 this is all I should have to do... The files are in the same directory, so the path should not be a problem ?

A: 

Last time I used SWIG, it generated two files. In your case it should be codes.py and _codes.so

You should check why codes.py is not present.

ascobol
Thats indeed the problem, there is no .py file. But I have no idea why, and googling doesn't seem to help. SWIG gives me one warning that might be relevant: " Warning(312): Nested struct not currently supported (ignored)", but I don't use nested structs (only one struct with ints), and since the .so file is generated, I suspect that is not the problem?
A: 

if you are executing these commands from the same place (directory) _codes.so ends up in . and codes.py ends up in ./codes/ , I think.

iondiode