Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Could this be good for converting Python 3 code back to Python 2 (to target CentOS 7 specifically)? The final code doesn't need to look nice, it just needs to run.


That sounds much more difficult than installing python 3 on centos 7. Why can't you do that instead?


Because that would mean all my customers have to find and install Python 3. Most of them won't allow EPEL packages to be installed because they're not supported, and even if they did there's a huge barrier to asking people to add an extra repository.


The difference between 2 and 3 is more than the language: the Stdlib changed as well, the data structure behavior as well, and some features are just not backward (e.g: unicode handling, async/await, etc).

Using Centos 7, I managed to install Python 3.6 (https://www.rosehosting.com/blog/how-to-install-python-3-6-4...) quite easily. And of course Python 3.4 is available in the EPEL repo if you need something more "official" (https://fedoraproject.org/wiki/EPEL).

But if you don't want your target machines to install anything, then use nuikta (http://nuitka.net/) on the dev machine to make a stand alone executable out of your python program, and distribute that.

The dev machine needs to be a centos 7 to make sure it will work on the targets (there are other possibilities, but more complicated). Other than that, you won't need to provide anything else. Python will be embedded in the resulting executable, will work transparently, and will not conflict with any existing setup.

As a bonus, the program will run up to 4 times faster, and won't need any admin rights to be installed.

Alternatively, you can use the python-future library (https://python-future.org) to make you program compatible with both python 2 and 3. But it's much more work.


Unlikely. The main difficult issue between python 2 and python 3 is in library changes, where features such as what type range() returns or the handling of Unicode strings impact code correctness. Transpilation would mostly be an issue of providing the expected library semantics along with a fairly simple AST transformation, which doesn't require the lossiness of compilation/decompilation.


Python 3.4 is available in the EPEL repository, which is usually a really good and stable source of packages.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: