/usr/bin/env python

Craig Treleaven ctreleaven at cogeco.ca
Sun Dec 16 20:06:20 PST 2012

At 9:41 PM -0600 12/16/12, Ryan Schmidt wrote:
>On Dec 16, 2012, at 14:49, Craig Treleaven wrote:
>>  At 12:10 AM +1100 12/17/12, Joshua Root wrote:
>>>  On 2012-12-16 19:46 , vincent habchi wrote:
>>>>  Some scripts of a port I'm trying to set up use #!/usr/bin/env 
>>>>python, which seem to always point to Apple's python. Which 
>>>>environment variable have I to change so that 'env' will return a 
>>>>MacPorts python instead?
>>>  There is no environment variable that will help here; 'python' is not
>>>  guaranteed to be present in ${prefix}/bin.
>>>  The reason /usr/bin/env is used in the shebang line here is that the
>>>  interpreter for a script must be an absolute path, but the author
>>>  doesn't know where python will be on the user's system. The env command
>>>  is for altering the environment, but is used without setting any
>>>  variables, and is thus a noop that gets around the absolute path
>>>  requirement. Only PATH has any effect on which python is found.
>>  For my edification...I see this all the time with Python but never 
>>Perl.  Is there some reason the former needs it and the latter 
>>doesn't?  Do other scripting languages require the env 'trick'?
>We usually want to use only MacPorts software, but this is not 
>enforced for little utilities like awk, sed and grep, and perl 
>sometimes fits into that category too. For one thing, perl has been 
>around for such a long time that every version of OS X MacPorts runs 
>on contains a sufficiently-new version of perl. The exception, and 
>the case when you definitely should depend on and ensure you're 
>executing a specific MacPorts perl, is when the script requires the 
>use of perl modules.
>perl is also unusual compared to the other multi-version scripting 
>languages in MacPorts in that we actually do have a port that 
>provides ${prefix}/bin/perl. That's an aberration, not something we 
>want to emulate elsewhere, and it should probably be changed: 

Sorry, Ryan, that wasn't what I was trying to ask about.  I 
understand about making sure that a port-specified versions of perl 
and python get used.  (Lord knows my mythtv-core.25 port would be a 
lot shorter if that wasn't required!)

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.


More information about the macports-dev mailing list