[Tutor] Re: python from shell

Derrick 'dman' Hudson dman@dman.ddts.net
Tue, 9 Jul 2002 11:38:48 -0500


--OwLcNYc0lM97+oe1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jul 09, 2002 at 09:18:25AM -0500, SA wrote:
| On 7/9/02 7:37 AM, "Scot W. Stevenson" <scot@possum.in-berlin.de> wrote:
|=20
| >> You have to add #! and the path of your python command in the first li=
ne
| >> of your code. In my case is:
| >> #! /usr/bin/python
| >=20
| > I've been using=20
| >=20
| > #!/usr/bin/env python
| >=20
| > instead with no ill effects so far - which, if I understand correctly,
| > gives the program the environment variables, too.
|
| The only problem I've seen with this so far is when I write a cgi script.
| For some reason /usr/bin/env chokes my Apache server and spews an error. =
In
| a regular python script, this works fine for me. I just changed that line=
 to
| the direct route to python for my cgi scripts.

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
linux/bash) that you can't pass any arguments to python itself (such
as -u or -OO).

Using the full path to the interpreter ensures that you'll be using
the python you want to use.

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.

Pay your money and take your choice :-) (as one of my profs likes to say)

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.


As for running as a CGI script in Apache, the problem is that $PATH
isn't set the same way it is in your shell.  Hence /usr/bin/env can't
find a 'python' and it fails.  Use the absolute path and it will work
as expected.

-D

--=20
=20
Religion that God our Father accepts as pure and faultless is this: to
look after orphans and widows in their distress and to keep oneself from
being polluted by the world.
        James 1:27
=20
http://dman.ddts.net/~dman/


--OwLcNYc0lM97+oe1
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj0rEZgACgkQO8l8XBKTpRTUBACcCDazxQsRPc3NcneWS2CNwgmS
LqgAn0T9jQYS2NLBw/ggM9TefJyc2npC
=fU+9
-----END PGP SIGNATURE-----

--OwLcNYc0lM97+oe1--