User: Password:
Subscribe / Log in / New account

Moving to Python 3

Moving to Python 3

Posted Feb 10, 2011 10:01 UTC (Thu) by talex (subscriber, #19139)
Parent article: Moving to Python 3

The new unicode handling looks good, but of course we have to wait a few years for the older distributions to include it. The main problem with Python 3 is that one distribution has decided that "python" is now "python3", breaking all existing scripts. Meanwhile, other distributions provide only "python" and not "python2". As far as I can see, every Python program that wants to support all distributions must now start with:

#!/usr/bin/env python
import sys
if sys.version_info[0] > 2:
        import os
        os.execvp("python2", ["python2"] + sys.argv)
# ... chain-load Python 2 code without using syntax that Python 3 will choke on
This is pretty horrible.

(Log in to post comments)

Moving to Python 3

Posted Feb 10, 2011 10:37 UTC (Thu) by tetromino (subscriber, #33846) [Link]

This is why Gentoo
(a) installs python executables as /usr/bin/pythonX.Y, with /usr/bin/python2 and /usr/bin/python3 as customizeable symlinks, and /usr/bin/python as a symlink to an intelligent wrapper controlled by eselect; and
(b) provides the python_convert_shebangs() function in the python eclass, allowing ebuild writers to easily change all the "#!/usr/bin/env python*" strings in the scripts in the package to call whichever python version is appropriate for that package.

Moving to Python 3

Posted Feb 18, 2011 21:03 UTC (Fri) by valhalla (subscriber, #56634) [Link]

Or you could use distutils / distribute, and then shebangs are taken care of at installation time.

Most PKGBUILD for said distribution just run python2 and everything works.

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds