python 找不到用 swig 编译的模块

发布于 2024-08-31 00:17:20 字数 773 浏览 3 评论 0原文

我对 SWIG 和 python 有疑问。我有一个可以正确编译的 c 类,但 python 脚本说它找不到该模块。

我编译:

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

这给了我一个 _codes.so 文件,正如我所期望的,但是我有这个 python 文件:

import sys
import codes

(rest of the code omitted)

它给了我:

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

根据 http://www.swig.org/Doc1.3/Introduction.html#Introduction_nn8 这就是我应该做的... 这些文件都在同一目录中,所以路径应该没有问题?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

单挑你×的.吻 2024-09-07 00:17:20

如果是发布版本,请将 _codes.so 重命名为 _codes.pyd。重命名为 _codes_d.pyd 以进行调试版本。

华泰

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

HTH

黑色毁心梦 2024-09-07 00:17:20

上次我使用 SWIG 时,它生成了两个文件。在你的情况下,它应该是codes.py和_codes.so

你应该检查为什么codes.py不存在。

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.

向日葵 2024-09-07 00:17:20

如果您从同一位置(目录)执行这些命令,_codes.so 将以 .我认为,codes.py 最终会出现在 ./codes/ 中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文