/usr/bin/env python

Lawrence Velázquez larry.velazquez at gmail.com
Sun Dec 16 21:44:49 PST 2012

On Dec 16, 2012, at 11:06 PM, Craig Treleaven <ctreleaven at cogeco.ca> wrote:

> I was just curious why a lot of the Python scripts I've run across use the env trick.  Sounds like it was a workaround as the path to the python executable was unpredictable on some systems.

A couple of possibilities come to mind.

(A) The way execve(2) tokenizes shebang lines is not standardized.[1] Given a file "foo.pl" starting with "#!/usr/bin/env perl -w", OS X and other BSDs execute /usr/bin/env with the args "perl", "-w", and "foo.pl", while Linux passes "perl -w" and "foo.pl".[2][3] Obviously, "perl -w" is not the name of an interpreter. If Perl scripts commonly include options in the shebang line, using /usr/bin/env could cause portability issues.

    [1] http://mail-index.netbsd.org/netbsd-users/2008/11/09/msg002388.html
    [2] https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/execve.2.html
    [3] http://man7.org/linux/man-pages/man2/execve.2.html

(B) It's fairly common to isolate Python programs and apps inside sandboxes like virtualenv, which install an interpreter and its associated libraries and modules inside a directory of your choosing. I don't know how common this sort of thing is in the Perl world.

(C) Could just be a chance cultural difference, for no good reason.


More information about the macports-dev mailing list