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

Adriano Ferreira a.r.ferreira at gmail.com
Fri Dec 2 09:12:19 EST 2005


On 12/2/05, Klaus Alexander Seistrup <klaus at seistrup.dk> wrote:
> #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)

Cheers,
Adriano.



More information about the Python-list mailing list