Running a python script under Linux

Hans Mulder hansmu at xs4all.nl
Fri Dec 14 15:59:47 CET 2012


On 14/12/12 14:38:25, D'Arcy J.M. Cain wrote:
> On Fri, 14 Dec 2012 14:18:28 +0100
> Hans Mulder <hansmu at xs4all.nl> wrote:
>> The Pythonic way to get what you want, is to be explicit:
>>
>> #!/usr/local/bin/python2.7 -V
>>
>> If you do that, it will even work in situations where you
>> can't control PATH, such as CGI scripts and cron jobs.
> 
> As long as you only run on one system that's OK.

As I understand it, the OP has a single system where the
system Python is CPython 2.4, and he has install 2.7 in
/usr/local/bin.

> That won't work on NetBSD or Linux[1] for example.

I would expect it to work, as long as /usr/local/bin/python2.7
exists and is a binary executable for the right architecture.

Why wouldn't it work?

It doesn't exceed the 32-character limit and it contains
only one option.  What other pitfalls are there?

>> There are situations where using #!/usr/bin/env makes sense,
>> but yours isn't one of them.
> 
> #! /usr/bin/env python2.7

On my box, that line might find a python2.7 in the
currently active virtualenv, which may have the wrong
set of third-party modules in its site-packages.

When I write a script that is meant to be used as a
utility, independent of which virtualenv is currently
active, then I'll make sure that its #! line points
at the Python2.7 install I used to test it.

> [1]: Well, Ubuntu anyway.  I don't know about the others.


Just curious,

-- HansM




More information about the Python-list mailing list