Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming for Python installations in Unix and good use of the shebang

I am confused about the standard way to write the shebang for a Python script.

I have a plain "python" link which depending on the system it could be either Python 2.x or Python 3.x and that is a problem since both are incompatible.

As a solution I write the version in my shebang and have something like:

#!/bin/env python3.2

But that seems foolish because it will prevent my script from running in any other 3.x release

I have noticed that some systems have python2 linked to the latest release. That helps, since that way I could write simple scripts, like "Hello World" which will not break with every release.

I have installed Python 2.6, 2.7, 3.1 and 3.2 Using just "python" for the shebang does not make sense from a portability point of view. Using the exact version hinders maintainability. I do have a python2 link, but not not a python3

Is there any standard and/or PEP specifying how Python should be installed? And one that says that I deploy to must have a python3 and/or python2 linked to the latest release?

like image 442
SystematicFrank Avatar asked Jul 21 '12 20:07

SystematicFrank


1 Answers

Almost anything that works with Python 2.x works with Python 2.7 unchanged. The same goes with Python 3.x and Python 3.2. Anything that doesn't should be changed (no really, it should).

Then it's simply the usual naming scheme:

Python 2.x

#!/usr/bin/env python

Python 3.x

#!/usr/bin/env python3
like image 188
orlp Avatar answered Nov 04 '22 21:11

orlp