简体   繁体   English

用python找不到的swig编译的模块

[英]module compiled with swig not found by python

I've a problem with SWIG and python. 我对SWIG和python有问题。 I've a c-class that compiles correctly, but the python script says it can't find the module. 我有一个可以正确编译的c类,但是python脚本说找不到该模块。

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: 正如我所期望的,这给了我一个_codes.so文件,但是我有了这个python文件:

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 ? 根据http://www.swig.org/Doc1.3/Introduction.html#Introduction_nn8的说明,这就是我所要做的...这些文件位于同一目录中,因此路径应该不是问题吗?

Last time I used SWIG, it generated two files. 上次使用SWIG时,它生成了两个文件。 In your case it should be codes.py and _codes.so 在您的情况下,应为code.py和_codes.so

You should check why codes.py is not present. 您应该检查为什么codes.py不存在。

if you are executing these commands from the same place (directory) _codes.so ends up in . 如果您是从同一位置(目录)执行这些命令,则_codes.so会以结尾。 and codes.py ends up in ./codes/ , I think. 我认为codes.py最终以./codes/结尾。

Rename your _codes.so to _codes.pyd if its a release build. 如果您的_codes.so是发行版,则将其重命名为_codes.pyd。 Rename to _codes_d.pyd for debug builds. 重命名为_codes_d.pyd进行调试。

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM