开发者

module compiled with swig not found by python

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 ?


Rename your _codes.so to _codes.pyd if its a release build. Rename to _codes_d.pyd for debug builds.

HTH


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜