What does "#!/usr/bin/env python" do?

Francis Avila francisgavila at yahoo.com
Mon Nov 10 08:13:22 CET 2003

"Parzival" <ConfuseYourSpamBot-parzp at ConfuseYourSpamBot.shaw.ca> wrote in
message news:_eGrb.358699$9l5.109956 at pd7tw2no...
> I am a now immigrant to Linux from (the old country)
> Can someone explain what the line:
> #!/usr/bin/env python
> at the start of a python script does? All my reading of
> bash and env manpages would lead me to believe that
> #!python
> is equivalent to the first line, but not speaking well the
> language am I, so here the question am I asking.

Not quite.  Bash (and I think most borne-ish shells) does not check the path
for hash-bangs, but expects an absolute pathname.  Now, the location of
python can vary widely, so we can't use an absolute pathname.  We could do
'/bin/sh -c python', but 1) hash-bangs only pass a single "word" as argument
(only '-' of '-c' would be passed) 2) that would start an unnecessary

Hence, /usr/bin/env.  It's almost always there, it looks in the path, it
doesn't start a subshell, and it doesn't need extra options to execute the
command.  Pretend it's windows' "start".

Francis Avila

More information about the Python-list mailing list