niner / inline-python-pm

Inline::Python - Write Perl subs and classes in Python.
https://metacpan.org/release/Inline-Python
20 stars 13 forks source link

Building Python 2 and Python 3 support in parallel #18

Open Conan-Kudo opened 7 years ago

Conan-Kudo commented 7 years ago

Currently, it looks like Inline::Python can only be built for one or the other.

Would you consider making it so that it can be built to provide Python 2 and Python 3 versions in one build?

I guess they would be Inline::Python2 and Inline::Python3, with all the equal capabilities of the original Inline::Python.

marghidanu commented 7 years ago

Use separate developments, something like local::lib. This way you can add multiple installations against different Python versions.

Zer0-Tolerance commented 5 years ago

Hi, Got the same need, I need to run python2 & python3 code at the same time. And having 2 instance of Inline::Python one binded on python2 and the other on python3 but it doesn't work because I guess they are using the same namespace from the C library.

Any idea how to build two different flavour ?

niner commented 5 years ago

There's just no way that Inline::Python could support Python 2 and Python 3 in the same program at the same time for the same reason that the switch to Python 3 requires you to upgrade all of your program including all libraries to Python 3. The Python interpreter uses the same symbol names (i.e. functions) in both versions and the linker gets confused by that.

There would actually have been a way for them to work around this: run Python 2 and Python 3 in different processes and forward calls and data over some kind of IPC mechanism. That's really not that different from how Inline::Python works (or Inline::Perl5 for example). If you really need to use both Python versions in a program, you could do the same.

As for supporting both Python version in a single build, that would certainly be possible. It would probably not even be all that hard. But it would be a major refactor of the build system and would require restructuring of the code, i.e. just a lot of work. I would definitely support someone doing this and be happy to take pull requests. Considering the existing workarounds (like local::lib) I just don't see this ever making it up far enough on my TODO list for me to do this all on my own. That we have Python 3 at all was due to the great work of @Imazuel