2011-07-27 58 views
5

我已经写在C我用SWIG生成的Java,Python等绑定我设法编写定制型两种语言等在地图上的一个库。我还设法使用我的库(一种自定义协议)并与我用C编写的服务器进行通信,并使用我用Java编写的客户端以及用Python编写的客户端进行通信。SWIG和Python3导入错误

最近,我遇到了一个多重继承问题,我发现一个solution聪明。但是,当试图使用Python 3复制错误时,错误消失了(解决了版本3中的也许)。事实是,相同的代码,相同的项目和相同的源代码不会调用python3二进制文件,但它的工作原理是调用python2.7二进制文件。

我得到的消息:

ImportError: dynamic module does not define init function (PyInit__pytellapic) 

这一点我已经读过什么可以从SWIG文档意味着一个稍微不同的错误:

import example 
Traceback (most recent call last): 
File "<stdin>", line 1, in ? 
ImportError: dynamic module does not define init function (init_example) 

话说:

This error is almost always caused when a bad name is given to the shared object file. For example, if you created a file example.so instead of _example.so you would get this error. Alternatively, this error could arise if the name of the module is inconsistent with the module name supplied with the %module directive. Double-check the interface to make sure the module name and the shared object filename match. Another possible cause of this error is forgetting to link the SWIG-generated wrapper code with the rest of your application when creating the extension module.

老实说,我认为这个可能的原因不适用于我的模块,因为它应该是2的错误。 7和3版本的Python,而不仅仅是Python 3.

我会很感激任何建议,但考虑到SWIG似乎是一个过时的项目,可能我会继续使用Python 2.7提到的“黑客”。

此致

回答

2

是否已经定义生成的C模块PyInit__pytellapic功能?

的名字和个人资料,如果模块init方法在Python 3已经改变如果你想完全相同的C代码双方的Python 2和Python 3下运行,你必须包括旧的和新的名称。有关更多信息,请参阅Migrating C Extensions一章。

根据SWIG's documentation痛饮2.0应该这样做,如果你通过-py3参数,但我还没有尝试过。

+0

在什么-py3参数的关注,我必须说,我已经尝试过没有成功。我也尝试了'swig -python -help'中列出的其他标志,但没有运气。在几分钟内(也许是几个小时),我在C扩展阅读。感谢您的指导和答复。 – Sebastian

+0

我添加了另一条评论,以避免混淆和混淆这一个。回答你的问题,我做了一个grep,结果如下:'#define SWIG_init PyInit__pytellapic'老实说,我不知道为什么我会得到那个错误。 – Sebastian

+0

@Sebastian:发布SWIG生成的代码可能会有所帮助,但我怀疑您需要在SWIG邮件列表上提问。从文件来看,你似乎做了正确的事情。 –