可能我的問題很明顯,但我無法找到明顯的決定。如何在Python 3中使用Python 2中的.so模塊?
有Python 2.6+擴展稱爲審計和auparse。這些都是動態庫分佈與審計庫的Python包:
[[email protected] tmp]$ repoquery -lq audit-libs-python
/usr/lib64/python2.7/site-packages/_audit.so
/usr/lib64/python2.7/site-packages/audit.py
/usr/lib64/python2.7/site-packages/audit.pyc
/usr/lib64/python2.7/site-packages/audit.pyo
/usr/lib64/python2.7/site-packages/auparse.so
我想因爲suspicions about the incorrect handling of dynamic memory in python 2.6+向上的最新Python解釋器使用該擴展。出於某種原因,我不能在Python 3.3加載它們:
[[email protected] ~]$ python3.3
Python 3.3.2 (default, Mar 5 2014, 08:21:05)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("/usr/lib64/python2.7/site-packages/")
>>> import auparse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib64/python2.7/site-packages/auparse.so: undefined symbol: _Py_ZeroStruct
>>> import audit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/audit.py", line 28, in <module>
_audit = swig_import_helper()
File "/usr/lib64/python2.7/site-packages/audit.py", line 24, in swig_import_helper
_mod = imp.load_module('_audit', fp, pathname, description)
File "/usr/lib64/python3.3/imp.py", line 183, in load_module
return load_dynamic(name, filename, file)
ImportError: /usr/lib64/python2.7/site-packages/_audit.so: undefined symbol: PyInstance_Type
我會很高興,如果有人能澄清引進這種的模塊融入現代Python解釋器的程序。很難相信第二和第三分支之間的向後兼容性在這種情況下也被破壞了。謝謝。