/usr/bin/env python

Joshua Root jmr at macports.org
Sun Dec 16 13:48:40 PST 2012


On 2012-12-17 07:49 , Craig Treleaven wrote:
> At 12:10 AM +1100 12/17/12, Joshua Root wrote:
>> On 2012-12-16 19:46 , vincent habchi wrote:
>>>  Folks,
>>>
>>>  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'?

There's no fundamental difference. Ports like eero-devel and tsung are
replacing '/usr/bin/env perl'.

- Josh


More information about the macports-dev mailing list