-1

I have generated a Python module using SWIG and Python 2.7 64 bit.

This Python module can successfully be imported (i.e. used) with this Python version, but when trying to import the module using a different Python version, let's say 3.5 64 bit, it fails.

Inversely, when I generate the same Python module using SWIG and Python 3.5 64 bit, it can successfully be imported (i.e. used) with this version, but not with Python 2.7 64 bit.

It would seem that SWIG generates a Python module just for that Python version that it was used upon the generation. Is this conclusion correct? If yes, what would be the approach to take to "tell" SWIG to generate a Python module that is Python version agnostic?

1
  • 1
    1) not related to the C language. 2) Why do you expect two different major versions of Python to have the same ABI? Oct 29, 2016 at 13:57

1 Answer 1

1

SWIG ultimately produces a Python extension which is inherently tied to a single version (and configuration) of Python.

SWIG itself is responsible only for the generation of code, not building it. It produces both C code to implement a Python extension, and a Python wrapper around that. Both of these outputs that SWIG generates should be version-agnostic.

When you actually compile the code however, you have to point it at an include path for your specific version of Python.

If you use setuptools to build everything, this mutiple-step process is somewhat hidden from you, as the include path for the Python version running the script is used automatically.

Look at 36.2.3 Hand compiling a dynamic module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.