How to specify Python version in script?

Javier Collado javier.collado at gmail.com
Wed Nov 11 19:28:37 CET 2009


Hello,

If you are working on linux, you can change the shebang line from:
#!/usr/bin/python

to:
#!/usr/bin/python2.6

Best regards,
    Javier

P.S. If you just want to avoid python 3 while running the latest
python 2.x version, this should also work:
#!/usr/bin/python2

2009/11/11 Benjamin Kaplan <benjamin.kaplan at case.edu>:
> On Wed, Nov 11, 2009 at 12:16 PM, kj <no.email at please.post> wrote:
>>
>>
>>
>>
>> I have a script that must be run with Python 2.6.x.  If one tries
>> to run it with, say, 2.5.x, *eventually* it runs into problems and
>> crashes.  (The failure is quicker if one attempts to run it with
>> Python 3.x.)
>>
>> Is there some way to specify at the very beginning of the script
>> the acceptable range of Python versions?
>>
>
> min_version = (2,6)
> import sys
> if sys.version_info < min_version :
>   print >> stderr, "must be run with at least Python 2.6"
>   sys.exit(1)
>
>
>> TIA!
>>
>> kynn
>>
>> P.S. I know that I can hardcode the path to a specific intpreter
>> in the #! line, but I'm trying to keep the code a bit more general
>> than that.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list