Depending on system, python==python2 or python==python3.

Executable Python scripts, starts with:

#!/usr/bin/env python
#!/usr/bin/env python2
#!/usr/bin/env python3...

For python py3k it is provided in documentation I should/can use it with version number, so I do this:

#!/usr/bin/env python3

But I've found a problem with py2k scripts.

While in py2k documentation it is written to use : #! /usr/bin/env python ,

on some *nix-es python py3k is default, so python==python3. (For example ArchLinux python package , here python package files).

How to package (configure,make) and/or prepare python scripts for distribution to handle that ?

I ask about making software packages that can be run easily by users (without modyfing their environment)

Can I do the same trick for python py2k scripts as for python py3k scripts and set it as : #!/usr/bin/env python2 ? Can I be sure that each python py2k distribution contains python2 file, so #!/usr/bin/env python2 will work ?

If yes, why it is not proposed as standard, for example in python py2k documentation ?

link|improve this question

59% accept rate
3  
As far as i know you can always use python2 to run it (if it installed), and alwayes you can check the version with python -V. if you want that python would be 2 or 3, you should rm /usr/bin/python and then create symlink that points from your desierd python version e.g ln -s /usr/bin/python2.5 /usr/bin/python. – Hanan N. Dec 11 '11 at 10:36
Thanks for ensuring me about python2. I wonder why is it not standard to use it when there is py2k and py3k and default python can differ. What about your advice about removing - it's not proper to this example, cause I ask about packaging. I'd like to make package that can run in different configurations/systems. No way about modifying environment. What about checking - it does not apply to Shebang - as far As I know. – Grzegorz Wierzowiecki Dec 11 '11 at 12:45
I believe what @Hanan N. is trying to tell you is that if you are writing Python 2.x code, then use #!...python2 in your programs and if you are using Python 3.x, then use #!...python3. Don't rely on the operating system to have the right link if you know it will only work on a specific release. I work with systems which still have Python 1.5.2 installed as /usr/bin/python - I either write code to handle older Python releases or use python2. – Arcege Dec 11 '11 at 18:07
1  
@Arcege I don't have a python2 executable on my system (Debian squeeze). python is a symlink to python2.6, and python3 is a symlink to python3.1, but there is no python2. – Gilles Dec 11 '11 at 23:07
1  
show 3 more comments
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.