Import fails with python 3.8 (M2Crypto from PyPI)
Python 3.8 replaced _PyObject_GC_UNTRACK by PyObject_GC_UnTrack (see commit to SWIG).
At least SWIG 4.0.1 is required to build M2Crypto compatible with Python 3.8.
With SWIG 4.0.0, M2Crypto still builds, but with a warning:
SWIG/_m2crypto_wrap.c: In function ‘SwigPyStaticVar_dealloc’:
SWIG/_m2crypto_wrap.c:2732:3: warning: implicit declaration of function ‘_PyObject_GC_UNTRACK’; did you mean ‘PyObject_GC_UnTrack’? [-Wimplicit-function-declaration]
2732 | _PyObject_GC_UNTRACK(descr);
| ^~~~~~~~~~~~~~~~~~~~
| PyObject_GC_UnTrack
And it fails on dynamic load:
Python 3.8.3 (default, May 14 2020, 15:17:37)
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from M2Crypto import RSA
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/venv/lib/python3.8/site-packages/M2Crypto/__init__.py", line 30, in <module>
from M2Crypto import (ASN1, AuthCookie, BIO, BN, DH, DSA, EVP, Engine, Err,
File "/tmp/venv/lib/python3.8/site-packages/M2Crypto/ASN1.py", line 15, in <module>
from M2Crypto import BIO, m2, py27plus, six
File "/tmp/venv/lib/python3.8/site-packages/M2Crypto/BIO.py", line 9, in <module>
from M2Crypto import m2, py27plus, six
File "/tmp/venv/lib/python3.8/site-packages/M2Crypto/m2.py", line 30, in <module>
from M2Crypto.m2crypto import *
File "/tmp/venv/lib/python3.8/site-packages/M2Crypto/m2crypto.py", line 26, in <module>
_m2crypto = swig_import_helper()
File "/tmp/venv/lib/python3.8/site-packages/M2Crypto/m2crypto.py", line 22, in swig_import_helper
_mod = imp.load_module('_m2crypto', fp, pathname, description)
File "/usr/lib/python3.8/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.8/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: /tmp/venv/lib/python3.8/site-packages/M2Crypto/_m2crypto.cpython-38-x86_64-linux-gnu.so: undefined symbol: _PyObject_GC_UNTRACK
M2Crypto from PyPI is built with SWIG older than 4.0.1, and it fails to load, like shown above.
Please rebuild the binaries in PyPI with SWIG 4.0.1 or later to make them compatible with Python 3.8. It's also a good idea to regenerate bindings in SWIG/ directory, as they still use _PyObject_GC_UNTRACK.