4

I am trying to use a library available on the web http://www.metarecognition.com/libmr-license/ via python. The authors have provided C code and swig interface file (*.i). The Make file provided by the users does not provide correct python compiling. So I tried to manually compile swig. I am using following commands after compiling the main library.

swig -python weibull.i
gcc -c ../libMR/weibull.c weibull_wrap.c -I/usr/include/python2.4 -fPIC
ld -shared weibull.o weibull_wrap.o -o _weibull.so

These steps work fine. But when I try to import it via python, I am getting following errors:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "pyweibullw.py", line 29, in <module>
    _pyweibullw = swig_import_helper()
  File "pyweibullw.py", line 21, in swig_import_helper
    import _pyweibullw
ImportError: /usr/lib/python2.4/dist-packages/_pyweibullw.so: undefined symbol: Py_InitModule4

Can somebody please tell me whats wrong? Am I making missing some flags for gcc? I have tried gcc with flags like -m64, --arch x86_64 but it doesnt seem to make any difference. FYI, I am using following system

bash-$:uname -a
Linux 2.6.32-5-amd64 #1 SMP Mon Oct 3 03:59:20 UTC 2011 x86_64 GNU/Linux
  • Ok I figured out what was happening. In modsupport.h in /usr/include/python/ you have to change the line from #define Py_InitModule4 Py_InitModule4TraceRefs to #define Py_InitModule4 Py_InitModule4_64 This is also a common problem in python 2.6 version, especially on AMD architectures. Guess they haven't fixed it. This puts the directive in library's memory and then it doesn't bitch about it anymore when you try to import. – abhijit bendale Sep 25 '12 at 19:34
  • This sounds a lot like http://stackoverflow.com/questions/4959872/py-initmodule4-with-djapian-xapian - did you compile something with Py_DEBUG defined? – gps Dec 26 '12 at 23:37

0 Answers0