[Tutor] Re: python from shell
Lloyd Kvam
pythontutor@venix.com
Wed, 10 Jul 2002 08:23:46 -0400
Using /usr/bin/env is generally best for people. This discussions started
because it failed for a CGI python script. A script that needs to run
using a server's environment may not have a "normal" path. Much depends on
the local security policies and the sysadmin. For those cases, if the
environment is totally outside your control, pointing directly to python
can be preferable.
lumbricus@gmx.net wrote:
>>On Tue, Jul 09, 2002 at 09:18:25AM -0500, SA wrote:
>>
>
> [ snip ]
>
>
>>Here's the difference :
>>
>>/usr/bin/env is a program that searches the $PATH to find the program
>>given as it's first argument. Then it exec's it on the input
>>(script).
>>
>>Using /usr/bin/env means that your script will automagically run on
>>any person's system *IFF* the 'python' found first in the $PATH is the
>>one you wanted to use. It also means (due to limitations in
>>
> ^^^^^^^^^^^
> what do you mean?
>
>
>>linux/bash)
>>
> ^^^^^^^^^^
> now which one?
>
>
>>that you can't pass any arguments to python itself (such
>>as -u or -OO).
>>
>
>>From 'man env' on OSF1
> (no matter which shell ;-)
>
> " env, printenv - Displays or sets the current environment, or displays the
> values of environment variables
>
> SYNOPSIS
>
> Current Syntax
>
> env [-i] [name=value...] [command] [args...]
>
> ...
>
> args
> Arguments to be passed to command when it is executed.
>
> "
>
> It works for me.
>
>
>>Using the full path to the interpreter ensures that you'll be using
>>the python you want to use.
>>
>
> _Iff_ it is there. On my system for example python is in
> /usr/local/bin. So your scripts won't run
>
>
>>For example, on a debian woody system, /usr/bin/python is a symlink to
>>/usr/bin/python2.1, and it is also possible for the user to have
>>/usr/bin/python2.2 as well. On a RH 7.x system, 'python' (is it in
>>/usr/bin ?) is version 1.5 wherease 'python2' is version
>>2.<something>. Using the env trick will yield different results on
>>different systems, and using the full path isn't compatible with all
>>systems.
>>
>
> ACK
>
>
>>Pay your money and take your choice :-) (as one of my profs likes to say)
>>
>
> But env(1) has the advantage that it sets the environment as the
> command (python) needs it - PYTHONPATH, PYTHONHOME or the like.
>
>
>>I choose to use the absolute path and explicitly specify the version I
>>want. Then again, I also use debian and for debian-packaged programs
>>that is also the Policy.
>>
>
> But this fails, if the specified version isn't there.
> I'd prefer env(1).
>
> [ snip ]
>
> HAND and Greetings,
> J"o!
>
>
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice:
603-443-6155
fax:
801-459-9582