2011-07-27 62 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郵件列表上提問。從文件來看,你似乎做了正確的事情。 –