Naming for Python installations on Unix and good use of shebang

I got confused in the standard way of writing a shebang for a Python script.

I have a simple python link, which may be Python 2.x or Python 3.x, depending on the system, and this is a problem, as both are incompatible.

As a solution, I am writing a version in my shebang and have something like:

#!/bin/env python3.2 

But this seems silly because it will prevent my script from running in any other version 3.x

I noticed that on some systems python2 is associated with the latest version. This helps as I could write simple scripts such as "Hello World" that would not interrupt with each version.

I installed Python 2.6, 2.7, 3.1 and 3.2. Using "python" for shebang does not make sense in terms of portability. Using the exact version makes maintainability difficult. I have a python2 link but not python3

Is there any standard and / or PEP indicating how Python should be installed? And the one that says I'm deploying should have python3 and / or python2 related to the latest version?

+8
python installation shebang
source share
1 answer

Almost everything that works with Python 2.x works with Python 2.7 unchanged. The same thing happens with Python 3.x and Python 3.2. Everything that should not be changed (in fact, it should not be).

Then this is just the usual naming scheme:

Python 2.x

 #!/usr/bin/env python 

Python 3.x

 #!/usr/bin/env python3 
+2
source share

All Articles