Porting Python2 C-API/Swig based modules to Python 3

Adam Pridgen adam.pridgen at thecoverofnight.com
Wed Feb 23 11:54:50 EST 2011


Hello,

I am trying to get a compiled module to work with Python3.  The code I
am compiling was originally intended to be used in a Python 2.*
environment, but I updated all the Python 2.* elements and the swig
commands used by the setup.py script.  I got the library to
successfully compile, but I am getting the following errors on import
(below).  I am not sure how to trouble shoot this problem, and the
fact that only one symbol (_PyCObject_FromVoidPtr) is missing is
disconcerting.  I Googled some, but the symbol mentioned only showed
up in a few posts, where linking was an issue.  I have also gone
through the setup.py script and explicitly defined all the library
paths.

My questions:

- Has anyone ever ported Python 2* modules/libs to Python 3 that rely
on swig, and are there some changes in the C-API/swig I need to be
looking for to make this port successful?

- Does anyone have any advice/insght about how I can troubleshoot,
diagnose, and resolve this issue?

Thanks in advance,

-- Adam


<error message>

0:pylibpcap-0.6.2$ python3
Python 3.2 (r32:88452, Feb 20 2011, 11:12:31)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcap,py
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/pcap.py",
line 25, in <module>
    _pcap = swig_import_helper()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/pcap.py",
line 21, in swig_import_helper
    _mod = imp.load_module('_pcap', fp, pathname, description)
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/_pcapmodule.so,
2): Symbol not found: _PyCObject_FromVoidPtr
  Referenced from:
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/_pcapmodule.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/_pcapmodule.so
>>> ^D



More information about the Python-list mailing list