Why use #!/usr/bin/env python rather than #!python?

Klaus Alexander Seistrup klaus at seistrup.dk
Fri Dec 2 09:17:35 EST 2005


Adriano Ferreira skrev:

>> #v+
>>
>> $ ls -l /tmp/hello.py
>> -rwxr-xr-x  1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py
>> $ cat /tmp/hello.py
>> #! python
>> print 'Hello, world!'
>> # eof
>> $ /tmp/hello.py
>> bash: /tmp/hello.py: python: bad interpreter: No such file or directory
>> $
>>
>> #v-
>
> Hey, that's not fair. In your illustration above, does 'python' can be
> found in the PATH? That is,
>
> $ python /tmp/hello.py
>
> works? If it does, probably
>
> #!/usr/bin/python
> #!/usr/bin/env python
> #!python
>
> would also work if
> (1) 'python' is at '/usr/bin/python' (but that's inflexible)
> (2) 'python' can be found in the environment variable path (if 'env'
> is at '/usr/bin/env')
> (3) 'python' can be found in the environment variable path (no need
> for 'env' utility)

Sure, I wasn't fair.  But look here:

#v+

$ python /tmp/hello.py
Hello, world!
$ which python
/usr/bin/python
$ 

#v-

I do not know the syntax of the shebang-line, but perhaps an absolute 
path is required?

PS: The "Mail-Copies-To: nobody" header line means that I do not wish 
to receive mail replies - please follow-up to group only.

Cheers,

-- 
Klaus Alexander Seistrup
Copenhagen, Denmark
http://streetkids.dk/



More information about the Python-list mailing list