Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-30 Thread Matej Cepl
On 28/09/12 12:57, Roy Smith wrote:
 But, you might as well get into the habit of 
 using the /usr/bin/env flavor because it's more flexible.

In the same manner as one's freedom-fighter is another's fundamentalist
terrorist, what's flexible could be also dangerous. E.g.,

#!/usr/bin/env python

is forbidden in the core Fedora packages
(https://fedoraproject.org/wiki/Features/SystemPythonExecutablesUseSystemPython),
because nobody is willing to risk that by some random python binary in
/usr/local/bin some core infrastructure of Fedora installations (e.g.,
yum) could be broken.

Matěj

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-28 Thread Jussi Piitulainen
Gilles writes:

 #!/usr/bin/env python
 #!/usr/bin/python
 
 What's the difference?

Not much if your python is /usr/bin/python: env looks for python and
finds the same executable.

When python is not /usr/bin/python but something else that is still
found by your system, /usr/bin/env still finds it.

For example, in a server where I work, python3 is installed as
something like /opt/python/3.2.2-gcc/bin/python3. There is no
/usr/bin/python3 at all, but #! /usr/bin/env python3 works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-28 Thread Roy Smith
In article 34va6856ocuas7jpueujscf3kdt7k44...@4ax.com,
 Gilles nos...@nospam.com wrote:

 Hello
 
 I've seen both shebang lines to run a Python script on a *nix host:
 
 #!/usr/bin/env python
 #!/usr/bin/python
 
 What's the difference?

The first one looks through your PATH to find the right python 
interpreter to run.  The second one is hard-wired to run /usr/bin/python.

If you only have a single copy of python installed, it doesn't really 
matter which you use.  But, you might as well get into the habit of 
using the /usr/bin/env flavor because it's more flexible.

I'm working on a number of different python projects.  For each one, I 
set up a new virtual environment using virtualenv.  This lets me run 
different versions of python in different projects, with different 
collections of installed packages (and possibly different versions).  I 
can only do this because I use the /usr/bin/env line in all my scripts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-28 Thread Gilles
On Fri, 28 Sep 2012 06:57:28 -0400, Roy Smith r...@panix.com wrote:
The first one looks through your PATH to find the right python 
interpreter to run.  The second one is hard-wired to run /usr/bin/python.

If you only have a single copy of python installed, it doesn't really 
matter which you use.  But, you might as well get into the habit of 
using the /usr/bin/env flavor because it's more flexible.

Thanks guys. I suspected that's what the difference was.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-28 Thread D'Arcy Cain
On Fri, 28 Sep 2012 06:57:28 -0400
Roy Smith r...@panix.com wrote:
  I've seen both shebang lines to run a Python script on a *nix host:
  
  #!/usr/bin/env python
  #!/usr/bin/python
  
  What's the difference?
 
 The first one looks through your PATH to find the right python 
 interpreter to run.  The second one is hard-wired to run /usr/bin/python.
 
 If you only have a single copy of python installed, it doesn't really 
 matter which you use.  But, you might as well get into the habit of 
 using the /usr/bin/env flavor because it's more flexible.

Not just flexible but portable.  On various systems I have Python
in /usr/bin, /usr/local/bin and /usr/pkg/bin.  #!/usr/bin/env python
finds it in each case so I only need one version of the script.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-28 Thread Gilles
On Fri, 28 Sep 2012 09:19:54 -0400, D'Arcy Cain da...@druid.net
wrote:
Not just flexible but portable.  On various systems I have Python
in /usr/bin, /usr/local/bin and /usr/pkg/bin.  #!/usr/bin/env python
finds it in each case so I only need one version of the script.

Good to know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-28 Thread Demian Brecht

On 12-09-28 06:19 AM, D'Arcy Cain wrote:

Not just flexible but portable.  On various systems I have Python
in /usr/bin, /usr/local/bin and /usr/pkg/bin.  #!/usr/bin/env python
finds it in each case so I only need one version of the script.



+1. This also resolves correctly on Cygwin, even if Python is installed 
via Windows installers (as long as it's on system PATH). Tremendously 
useful if you're bouncing between *nix and Windows regularly.


--
Demian Brecht
@demianbrecht
http://demianbrecht.github.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-09 Thread Tim Roberts
Brian Vanderburg II [EMAIL PROTECTED] wrote:
D'Arcy J.M. Cain wrote:
 Brian Vanderburg II [EMAIL PROTECTED] wrote:
   
 This is sort of related, but I'm wondering what is different between 
 #!/usr/bin/env python and #!python.  Wouldn't the second do the same 
 thing, since an absolute path is not specified, find 'python' from the 
 PATH environment,  I don't really know.

 Well, I know what happened when I tried it.  What happened when you
 tried it?
   
I haven't tried it but I've seen some files like written that in the 
past with just a name and no path for some other interpreter (perl or sh 
probably) and didn't know what the different was or if it was even 
valid. 

It's not valid.  The shebang line (#!) must specify a full path.  When you
saw the lone word (perl), it was probably a /usr/bin/env line, just we
have been discussing.

I at a windows system now so I can't try it yet.

*IF* you are interested in playing with Linux, most of the distributions
have bootable CDs that will bring up a full Linux environment without ever
touching your hard disk.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-08 Thread Brian Vanderburg II
This is sort of related, but I'm wondering what is different between 
#!/usr/bin/env python and #!python.  Wouldn't the second do the same 
thing, since an absolute path is not specified, find 'python' from the 
PATH environment,  I don't really know.


Brian Vanderburg II
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-08 Thread Michael Mabin
For me, the difference is #!python doesn't work for me.  I get a bad
interpreter error.

On Thu, May 8, 2008 at 6:31 AM, Brian Vanderburg II 
[EMAIL PROTECTED] wrote:

 This is sort of related, but I'm wondering what is different between
 #!/usr/bin/env python and #!python.  Wouldn't the second do the same
 thing, since an absolute path is not specified, find 'python' from the PATH
 environment,  I don't really know.

 Brian Vanderburg II

 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-08 Thread D'Arcy J.M. Cain
On Thu, 08 May 2008 07:31:17 -0400
Brian Vanderburg II [EMAIL PROTECTED] wrote:
 This is sort of related, but I'm wondering what is different between 
 #!/usr/bin/env python and #!python.  Wouldn't the second do the same 
 thing, since an absolute path is not specified, find 'python' from the 
 PATH environment,  I don't really know.

Well, I know what happened when I tried it.  What happened when you
tried it?

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-08 Thread Brian Vanderburg II

D'Arcy J.M. Cain wrote:

On Thu, 08 May 2008 07:31:17 -0400
Brian Vanderburg II [EMAIL PROTECTED] wrote:
  
This is sort of related, but I'm wondering what is different between 
#!/usr/bin/env python and #!python.  Wouldn't the second do the same 
thing, since an absolute path is not specified, find 'python' from the 
PATH environment,  I don't really know.



Well, I know what happened when I tried it.  What happened when you
tried it?

  
I haven't tried it but I've seen some files like written that in the 
past with just a name and no path for some other interpreter (perl or sh 
probably) and didn't know what the different was or if it was even 
valid.  I at a windows system now so I can't try it yet.


Brian Vanderburg II
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-06 Thread Banibrata Dutta
On 5/6/08, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 At our site we run  IRIX, UNICOS, Solaris, Tru64, Linux, cygwin and
 other unixy OSes.

 We have python installed in a number of different places:
 /bin/python
 /usr/local/bin/python
 /usr/bin/python
 /opt/freeware/Python/Python-2.5.1/bin/python
 ~mataap/platform/python/python-2.5.1

 So I cannot assume a single location for python.  Nor for any other
 tool, really.  Bash for example.  It may indeed be in /usr/bin on many
 systems, on many others it is not.

 Note the version specific install points.  This allows us to switch
 over easily to different versions, and keep older versions in case
 they are needed.  We can test new versions before cutting over to them
 operationally. (This matters for tools that are still changing, like
 python or bash.)

 We use the very handy 'modules' package (not python modules, not
 fortran modules) to adjust our paths and environment variables as
 needed.

 Some of the install points are determined by policy, or historical
 constraints, or hardware limits, or file system layout.

 Now it is true that it is easy to edit a single script to change the
 hashbang line.  It is not easy to change several hundred scripts, on
 different machines.  It is easy to adjust the environment to point to
 the right python path, and have all your scripts pick it up
 automatically.

Looks reasonable thing to do...


 Use /usr/bin/env.  If env is not in /usr/bin, put a link to it there.

So why not put symlink to Python over there on all machines, if we can
put one (or env itself) there ?

-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-06 Thread Wojciech Walczak
2008/5/6, Banibrata Dutta [EMAIL PROTECTED]:
   Use /usr/bin/env.  If env is not in /usr/bin, put a link to it there.

  So why not put symlink to Python over there on all machines, if we can
  put one (or env itself) there ?

To avoid linking all the rest of interpreters like perl, ruby, lua and dozens
of others.

-- 
Regards,
Wojtek Walczak
http://www.stud.umk.pl/~wojtekwa/
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-06 Thread Ben Finney
Wojciech Walczak [EMAIL PROTECTED] writes:

 2008/5/6, Banibrata Dutta [EMAIL PROTECTED]:
Use /usr/bin/env.  If env is not in /usr/bin, put a link to it there.
 
   So why not put symlink to Python over there on all machines, if
   we can put one (or env itself) there ?
 
 To avoid linking all the rest of interpreters like perl, ruby, lua
 and dozens of others.

The argument was being made from thousands of scripts. Isn't dozens
of symlinks better?

-- 
 \  It is difficult to get a man to understand something when his |
  `\ salary depends upon his not understanding it. —Upton |
_o__)   Sinclair, 1935 |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-06 Thread Wojciech Walczak
2008/5/6, Ben Finney [EMAIL PROTECTED]:
 So why not put symlink to Python over there on all machines, if
 we can put one (or env itself) there ?
  To avoid linking all the rest of interpreters like perl, ruby, lua
   and dozens of others.
 The argument was being made from thousands of scripts. Isn't dozens
  of symlinks better?

I think that depending on /usr/bin/env is more farsighted and saves some future
headaches. Creating links in /usr/bin/ means, that you have to change them
whenever you update your software (e.g. any of your many interpreters ;-)).
Changing the #!/usr/bin/python into #!/usr/bin/env python means that you do
your job once, and you can sleep well. It also is more portable.

How was it in perl?
perl -p -i -e 's/#\!\/usr\/bin\/python/#\!\/usr\/bin\/env python/' *.py

Funny thing, I have just ls'ed /usr/bin/python on my system:
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 2007-11-16 14:02 /usr/bin/python -
/usr/local/bin/python2.5

:-)

-- 
Regards,
Wojtek Walczak
http://www.stud.umk.pl/~wojtekwa/
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-06 Thread Ethan Furman

Banibrata Dutta wrote:


On 5/6/08, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 


At our site we run  IRIX, UNICOS, Solaris, Tru64, Linux, cygwin and
other unixy OSes.

We have python installed in a number of different places:
/bin/python
/usr/local/bin/python
/usr/bin/python
/opt/freeware/Python/Python-2.5.1/bin/python
~mataap/platform/python/python-2.5.1

So I cannot assume a single location for python.  Nor for any other
tool, really.  Bash for example.  It may indeed be in /usr/bin on many
systems, on many others it is not.

Note the version specific install points.  This allows us to switch
over easily to different versions, and keep older versions in case
they are needed.  We can test new versions before cutting over to them
operationally. (This matters for tools that are still changing, like
python or bash.)

We use the very handy 'modules' package (not python modules, not
fortran modules) to adjust our paths and environment variables as
needed.

Some of the install points are determined by policy, or historical
constraints, or hardware limits, or file system layout.

Now it is true that it is easy to edit a single script to change the
hashbang line.  It is not easy to change several hundred scripts, on
different machines.  It is easy to adjust the environment to point to
the right python path, and have all your scripts pick it up
automatically.
   



Looks reasonable thing to do...

 


Use /usr/bin/env.  If env is not in /usr/bin, put a link to it there.
   



So why not put symlink to Python over there on all machines, if we can
put one (or env itself) there ?

A symlink directly to python (or whatever) would not help when testing 
version x.y.z, while still leaving version a.b.c in place for the other 
tools/scripts/programs to keep using.

--
Ethan
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-06 Thread andrej . panjkov
On May 6, 9:06 pm, Ben Finney [EMAIL PROTECTED]
wrote:
 Wojciech Walczak [EMAIL PROTECTED] writes:
  2008/5/6, Banibrata Dutta [EMAIL PROTECTED]:
 Use /usr/bin/env.  If env is not in /usr/bin, put a link to it there.

So why not put symlink to Python over there on all machines, if
we can put one (or env itself) there ?

  To avoid linking all the rest of interpreters like perl, ruby, lua
  and dozens of others.

 The argument was being made from thousands of scripts. Isn't dozens
 of symlinks better?


It depends on single user vs multi user.  We keep multiple versions of
packages because some software requires the older versions.  Which
version do we symlink to?  What if we simultaneously require access to
two different versions?  For example, to keep legacy software going,
or to test updated versions while keeping operational versions
running.
What if we have shared file systems, and we have multiplatform
versions?  Python for solaris, python for tru64?

In a sense, we do have dozens of virtual links, using the modules
package to adjust paths on the fly.  This is more flexible than having
a static symlink in /usr/bin.  It allows us to select on a per user,
per process, per script basis, the python we want, version, platform
etc.  With a static symlink, every user/process/job gets the same
python, unless you want to flip symlinks around.

Also, every 10 years or so, each platform gets replaced, so we are
replacing platforms here every few years.  And we don't always get the
same replacement system.  Sure we can go in and  touch up all the
scripts.  But it just seems so much easier and flexible to tell a
python/bash/other script to use what you get from the path, and set
the paths.

Of course, things are different on a single user desktop system, with
its own filesystems.  If you are sure where python is, and you only
have one python, and you don't mind revisiting your scripts and
editing them if things change, by all means hard code the python path
in.

A
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-05 Thread andrej . panjkov
At our site we run  IRIX, UNICOS, Solaris, Tru64, Linux, cygwin and
other unixy OSes.

We have python installed in a number of different places:
/bin/python
/usr/local/bin/python
/usr/bin/python
/opt/freeware/Python/Python-2.5.1/bin/python
~mataap/platform/python/python-2.5.1

So I cannot assume a single location for python.  Nor for any other
tool, really.  Bash for example.  It may indeed be in /usr/bin on many
systems, on many others it is not.

Note the version specific install points.  This allows us to switch
over easily to different versions, and keep older versions in case
they are needed.  We can test new versions before cutting over to them
operationally. (This matters for tools that are still changing, like
python or bash.)

We use the very handy 'modules' package (not python modules, not
fortran modules) to adjust our paths and environment variables as
needed.

Some of the install points are determined by policy, or historical
constraints, or hardware limits, or file system layout.

Now it is true that it is easy to edit a single script to change the
hashbang line.  It is not easy to change several hundred scripts, on
different machines.  It is easy to adjust the environment to point to
the right python path, and have all your scripts pick it up
automatically.

Use /usr/bin/env.  If env is not in /usr/bin, put a link to it there.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-03 Thread Ben Finney
Ben Finney [EMAIL PROTECTED] writes:

 The shebang line (the initial line of the file beginning with #!)
 takes advantage of OS kernels that determine how to execute a file
 based on the first few bytes of the file. The shebang line tells the
 kernel that this file should be executed by passing it as input to a
 process started by another command.
 
 The specified command takes the form of a fully-qualified file path,
 and zero or one arguments to the program. That command is then
 executed by the kernel, and the Python program file is passed as
 input to the resulting process.

As was pointed out later in the thread, this description is partially
untrue. The program isn't passed as input to the interpreter.

Instead, the path to the program is appended as a command-line
argument to the interpreter. Thus the kernel starts a command of the
form:

word after the shebang optional single argument after the first word 
path to the program

Examples:

filename:  /home/foo/bar.py
shebang line:  #! /usr/bin/python
command line invoked:  /usr/bin/python /home/foo/bar.py

filename:  /home/foo/Makefile
shebang line:  #! /usr/bin/make -f
command line invoked:  /usr/bin/make -f /home/foo/Makefile

For more information on shebang processing, see
URL:http://foldoc.org/index.cgi?shebang for a basic description, and
URL:http://www.in-ulm.de/~mascheck/various/shebang/ for lots of gory
detail.

-- 
 \   There's no excuse to be bored. Sad, yes. Angry, yes. |
  `\Depressed, yes. Crazy, yes. But there's no excuse for boredom, |
_o__)   ever.  -- Viggo Mortensen |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-03 Thread Torsten Bronger
Hallöchen!

Gabriel Genellina writes:

 [...]

 I can't believe some angry responses in this thread - it's just a
 technical question, not about which is the best team in the
 [preferred sports here] National Championship...

Well, Python-list is tunnelled to Usenet.  Welcome here.  ;-)

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-03 Thread Lou Pecora
In article [EMAIL PROTECTED],
 Grant Edwards [EMAIL PROTECTED] wrote:

 On 2008-05-02, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote:
  On Sat, 03 May 2008 00:44:00 +1000
  Ben Finney [EMAIL PROTECTED] wrote:
  D'Arcy J.M. Cain [EMAIL PROTECTED] writes:
   As someone else pointed out, not all the world is Linux.
  
  It's a good thing I've never implied such to be the case.
 
  You haven't *said* it but you have definitely *implied* it.
  Installing Python in /usr/bin is not common.
 
 It is common.  That's where it's installed by almost all Linux
 distributions.

MacOS X system python (or links to them) is in the same place.

-- 
-- Lou Pecora
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-03 Thread Michael Mabin
I work on an AIX system where /usr/bin and /usr/local/bin apps can only be
installed by root. Our system doesn't have python or many other tools we
like to use installed so we have to install python in an alternate directory
location. We have a system installation of Perl installed, but it's a
release or two older than what we need, so we have done the same for perl.
Thus, #!/usr/bin/env whatever allows our developers to experiment without
always requiring the services of the admins, who are spread too thinly
amongst all the other *Nixes they have to support, and who are also
separated by many layers of red tape from us.

On Sat, May 3, 2008 at 10:24 AM, Lou Pecora [EMAIL PROTECTED]
wrote:

 In article [EMAIL PROTECTED],
  Grant Edwards [EMAIL PROTECTED] wrote:

  On 2008-05-02, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote:
   On Sat, 03 May 2008 00:44:00 +1000
   Ben Finney [EMAIL PROTECTED][EMAIL PROTECTED]
 wrote:
   D'Arcy J.M. Cain [EMAIL PROTECTED] writes:
As someone else pointed out, not all the world is Linux.
  
   It's a good thing I've never implied such to be the case.
  
   You haven't *said* it but you have definitely *implied* it.
   Installing Python in /usr/bin is not common.
 
  It is common.  That's where it's installed by almost all Linux
  distributions.

 MacOS X system python (or links to them) is in the same place.

 --
 -- Lou Pecora
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-03 Thread Aahz
In article [EMAIL PROTECTED],
Gabriel Genellina [EMAIL PROTECTED] wrote:

I can't believe some angry responses in this thread - it's just a  
technical question, not about which is the best team in the [preferred  
sports here] National Championship...

http://www.netfunny.com/rhf/jokes/91q3/usolym.html
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Help a hearing-impaired person: http://rule6.info/hearing.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Jeroen Ruigrok van der Werven
-On [20080502 07:51], Ben Finney ([EMAIL PROTECTED]) wrote:
To my mind, the Python interpreter installed by a package as
distributed with the OS *is* OS territory and belongs in /usr/bin/.

That's the difference with a distribution, such as Linux, and full OSes ,
such as BSDs or commercial Unix variants. They prefer to keep a pristine
state for the OS vendor files versus what the user can opt to install
himself, hence the /usr/bin - /usr/local/bin separation. Same for sbin, lib,
and so on. It effectively guarantees you can nuke /usr/local without ill
consequences for your OS.

Different philosophies, but after having spent more than 10+ years on too
many Unix and Unix-like systems I know the importance of platform
portability a bit too much and hardcoding a shebang sequence is not the
solution in general. Using env is the, arguably, best solution available.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Felix, qui potuit rerum cognoscere causas...
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Duncan Booth
Yves Dorfsman [EMAIL PROTECTED] wrote:

 On UNIX, some people use
 #!/usr/bin/env python
 
 While other use
 #!/usr/bin/python
 
 Why is one preferred over the other one ?
 
I don't think the answers so far have communicated what I believe to be the 
important point: it isn't that one is always better than the other, it 
depends on what you are trying to achieve.

The first one runs the Python found from the environment. This means you 
can write a script and expect it to run on systems configured differently. 
You might prefer in some cases to specify a particular version of Python:

#!/usr/bin/env python2.5

The second one runs a specific copy of Python (and here it is even more 
likely that you'll want to specify a particular version). This is important 
if your program is being run as a service or some other background 
situation where the environment isn't set up. For example Subversion hooks 
all run with an empty environment, and cron jobs run with a default 
environment which may not include python (e.g. if it is in /usr/local/bin).


--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Ben Finney
Jeroen Ruigrok van der Werven [EMAIL PROTECTED] writes:

 -On [20080502 07:51], Ben Finney ([EMAIL PROTECTED]) wrote:
 To my mind, the Python interpreter installed by a package as
 distributed with the OS *is* OS territory and belongs in /usr/bin/.
 
 That's the difference with a distribution, such as Linux, and full
 OSes , such as BSDs or commercial Unix variants. They prefer to keep
 a pristine state for the OS vendor files versus what the user can
 opt to install himself, hence the /usr/bin - /usr/local/bin
 separation.

Fine so far. /usr/local/ is certainly for what the (system
administrator) user opts to install themselves.

 It effectively guarantees you can nuke /usr/local without ill
 consequences for your OS.

You say this as though it's a property that a GNU/Linux distribution
doesn't have. But the keep /usr/local/ untouched by OS packages
approach taken by GNU/Linux *also* means that /usr/local/ can be blown
away without ill consequences for the OS. So I don't see why you draw
that distinction here.

The difference seems to be that Python is an OS-installable package on
GNU/Linux, and thus gets installed to the OS-packaged location. So the
default Python installation should work.

Whereas if Python is *not* installed from an OS package, it's up to
the sys admin to ensure that it works -- not up to my program. So I
don't see the point in making it work by default, when what I want for
my program is that it works *with the default Python*, not with some
non-default installation.

-- 
 \   Truth is stranger than fiction, but it is because fiction is |
  `\ obliged to stick to possibilities, truth isn't.  -- Mark |
_o__)   Twain, _Following the Equator_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread D'Arcy J.M. Cain
On Fri, 02 May 2008 15:50:22 +1000
Ben Finney [EMAIL PROTECTED] wrote:
  You have lived a sheltered life.  Not every packaging system puts the
  executible in /usr/bin.  Many systems use /usr/local/bin.
 
 They use that for the operating-system-installed default Python
 interpreter? Colour me incredulous.

OK, let me get out my crayons.  However, note that I did not say
operating-system-installed.  I said a packaging system puts it
there.  In fact, the NetBSD packaging system works on many systems
including Linux and thus is not an operating system packager.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Ben Finney
D'Arcy J.M. Cain [EMAIL PROTECTED] writes:

 On Fri, 02 May 2008 13:24:01 +1000
 Ben Finney [EMAIL PROTECTED] wrote:
  I much prefer #! /usr/bin/python because I want my Python
  programs to, by default, be run with the default Python, and
  depend on Python being installed by the operating system's package
  manager. On systems that use shebang lines and that actually have
  standardised filesystem locations, the default Python is found at
  '/usr/bin/python'.
 
 You have lived a sheltered life.  Not every packaging system puts the
 executible in /usr/bin.  Many systems use /usr/local/bin.

D'Arcy J.M. Cain [EMAIL PROTECTED] writes:

 On Fri, 02 May 2008 15:50:22 +1000
 Ben Finney [EMAIL PROTECTED] wrote:
  They use that for the operating-system-installed default Python
  interpreter? Colour me incredulous.
 
 OK, let me get out my crayons.  However, note that I did not say
 operating-system-installed.

That is, however, the context I've been explicitly using since this
sub-thread began.

The OP was asking why people prefer on over the other. My answer is
that I prefer specifying give me the default OS Python because
anything not installed by the OS is to non-standardised for me to
worry about.

Others may prefer something different, but then they get to wear
whatever problems occur as a result of that choice. I continue to be
bemused by that preference, and nothing that I've seen so far in this
thread illuminates the issue more.

-- 
 \ Nothing so needs reforming as other people's habits.  -- Mark |
  `\   Twain, _Pudd'n'head Wilson_ |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Thorsten Kampe
* Ben Finney (Fri, 02 May 2008 23:30:01 +1000)
 The OP was asking why people prefer on over the other. My answer is
 that I prefer specifying give me the default OS Python because
 anything not installed by the OS is to non-standardised for me to
 worry about.
 
 Others may prefer something different, but then they get to wear
 whatever problems occur as a result of that choice. I continue to be
 bemused by that preference, and nothing that I've seen so far in this
 thread illuminates the issue more.

You're missing the point. Apart from the really dubious terms you use 
(OS installable package), using env in the first line has exactly the 
effect to use the default path of Python (which is the first entry in 
your path) and not some hard-coded path (which might not even exist).

Thorsten
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Roy Smith
In article [EMAIL PROTECTED],
 Ben Finney [EMAIL PROTECTED] wrote:

 Whereas if Python is *not* installed from an OS package, it's up to
 the sys admin to ensure that it works -- not up to my program. So I
 don't see the point in making it work by default, when what I want for
 my program is that it works *with the default Python*, not with some
 non-default installation.

Ben,

Have you ever shipped software to a customer?  Imagine the following 
conversation:

Customer: Your product is broken.  It says it can't find python, and I 
know I have it installed.

Vendor: Where do you have it installed?

Customer: In /opt/bin/python

Vendor: Oh, that's your problem, it HAS to be in /usr/bin/python.

Customer: I can't install it there because insert whatever silly reason 
the customer has.  If you can't make your product work without requiring 
me to install python in /usr/bin, I'm afraid I can't buy your product.

Vendor: No problem sir, I'll be happy to tell our sales folks to stop 
bothering you.

If you want to hard-code /usr/bin/python into your application, that's your 
decision.  If you would like to take on the task of convincing every 
sysadmin in the world to do things the way you think they should be done, 
have fun.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread D'Arcy J.M. Cain
On Fri, 02 May 2008 23:30:01 +1000
Ben Finney [EMAIL PROTECTED] wrote:
 The OP was asking why people prefer on over the other. My answer is
 that I prefer specifying give me the default OS Python because
 anything not installed by the OS is to non-standardised for me to
 worry about.

As someone else pointed out, not all the world is Linux.  So your
version of Linux (I'm not sure whether it is true for all versions or
not) delivers Python as part of the OS.  That is simply not true of the
whole world.  Some OS distributions have an adjunct facility for
installing packages but they are not part of the OS.  Some systems
don't even have that and people must download packages such as Python
and install them manually.  Even on Linux there are people who won't
install binaries and use NetBSD's pkgsrc instead.  Clearly that cannot
install into /usr/bin since it is not part of the OS.

Certainly #! /usr/bin/python is fine if you never expect your software
to run outside of your own little corner of the world but you asked why
people prefer the env version and the answer is that we want to write
software that runs everywhere that Python runs.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Torsten Bronger
Hallöchen!

D'Arcy J.M. Cain writes:

 On Fri, 02 May 2008 23:30:01 +1000
 Ben Finney [EMAIL PROTECTED] wrote:

 The OP was asking why people prefer on over the other. My answer
 is that I prefer specifying give me the default OS Python
 because anything not installed by the OS is to non-standardised
 for me to worry about.

 [...]

 Certainly #! /usr/bin/python is fine if you never expect your
 software to run outside of your own little corner of the world but
 you asked why people prefer the env version and the answer is that
 we want to write software that runs everywhere that Python runs.

Granted, but you must draw the line somewhere anyway.  I cannot
pollute my program with hundreds of if clauses just to make it work
on every quirky system.  It's the *systems* where the streamlining
must happen, not the programs.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Ben Finney
Thorsten Kampe [EMAIL PROTECTED] writes:

 * Ben Finney (Fri, 02 May 2008 23:30:01 +1000)
  The OP was asking why people prefer on over the other. My answer
  is that I prefer specifying give me the default OS Python
  because anything not installed by the OS is to non-standardised
  for me to worry about.
  
  Others may prefer something different, but then they get to wear
  whatever problems occur as a result of that choice. I continue to
  be bemused by that preference, and nothing that I've seen so far
  in this thread illuminates the issue more.
 
 You're missing the point. Apart from the really dubious terms you
 use (OS installable package), using env in the first line has
 exactly the effect to use the default path of Python (which is the
 first entry in your path)

No, because it's quite common for the PATH variable to have
'/usr/local/bin' appear *before* both of '/bin' and '/usr/bin'.

If the system has a sysadmin-installed '/usr/local/bin/python'
installed as well as the OS-installed '/usr/bin/python', then the two
shebang options the OP raised will behave differently on such a
system. This seems to be quite the point of the discussion.

-- 
 \  Time's fun when you're having flies.  -- Kermit the Frog |
  `\   |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Grant Edwards
On 2008-05-02, Ben Finney [EMAIL PROTECTED] wrote:

 The specified command takes the form of a fully-qualified file
 path, and zero or one arguments to the program. That command
 is then executed by the kernel, and the Python program file is
 passed as input to the resulting process.

Just to clarify that a bit a little, the name of the file (as
it was given to the exec system call) containing the shebang
line is passed to the resulting process as a command-line
parameter.

 Why is one preferred over the other one ?

 I've never clearly understood why people want to use #! /usr/bin/env
 python, which is prone to finding a different Python from the one
 installed by the operating system. I'd be interested to see what
 responses are in favour of it, and what the reasoning is.

 One possible reason is that the programmer is attempting to allow for
 systems where Python has been installed, but not from an operating
 system package.

Exactly.  the env approach works as long as python is
installed somewhere on the PATH.  #!/usr/bin/python will fail
if python is installed in /usr/local/bin/python.

-- 
Grant

--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Ben Finney
Roy Smith [EMAIL PROTECTED] writes:

 In article [EMAIL PROTECTED],
  Ben Finney [EMAIL PROTECTED] wrote:
 
  Whereas if Python is *not* installed from an OS package, it's up
  to the sys admin to ensure that it works -- not up to my program.
  So I don't see the point in making it work by default, when what I
  want for my program is that it works *with the default Python*,
  not with some non-default installation.
 
 Ben,
 
 Have you ever shipped software to a customer?

Yes, and all parties have been quite happy with the results.

 Imagine the following conversation:
 
 Customer: Your product is broken. It says it can't find python, and
 I know I have it installed.
 
 Vendor: Where do you have it installed?
 
 Customer: In /opt/bin/python
 
 Vendor: Oh, that's your problem, it HAS to be in /usr/bin/python.

At this point the vendor isn't me, because this statement isn't true.
See below.

 Customer: I can't install it there because insert whatever silly
 reason the customer has. If you can't make your product work
 without requiring me to install python in /usr/bin, I'm afraid I
 can't buy your product.

At this point they have the simple option of running the program with
'python /path/to/the/program'. It's certainly not a case of can't
make the product work.

It is, however, a case of can't automatically account for every local
customisation sysadmins choose to make on their systems. Perfectly
willing to work with them to get their specific environment working,
but as a matter of simple economics it's not worth my time to attempt
to make such corner cases work automatically.

 If you want to hard-code /usr/bin/python into your application,
 that's your decision. If you would like to take on the task of
 convincing every sysadmin in the world to do things the way you
 think they should be done, have fun.

If they've already chosen to install Python to some unpredictable
location, they know what they're doing enough to invoke the program in
a specific way to get it working.

-- 
 \ Rommel: Don't move, or I'll turn the key on this can of Spam! |
  `\ -- The Goon Show, _Rommel's Treasure_ |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Ben Finney
D'Arcy J.M. Cain [EMAIL PROTECTED] writes:

 On Fri, 02 May 2008 23:30:01 +1000
 Ben Finney [EMAIL PROTECTED] wrote:
  The OP was asking why people prefer on over the other. My answer
  is that I prefer specifying give me the default OS Python
  because anything not installed by the OS is [too] non-standardised
  for me to worry about.
 
 As someone else pointed out, not all the world is Linux.

It's a good thing I've never implied such to be the case.

-- 
 \ If nature has made any one thing less susceptible than all |
  `\others of exclusive property, it is the action of the thinking |
_o__)   power called an idea  -- Thomas Jefferson |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Grant Edwards
On 2008-05-02, Jeroen Ruigrok van der Werven [EMAIL PROTECTED] wrote:

I've never clearly understood why people want to use #! /usr/bin/env
python, which is prone to finding a different Python from the one
installed by the operating system. I'd be interested to see what
responses are in favour of it, and what the reasoning is.

 Simple, some systems are not as peculiar as a lot of Linux boxes which
 chug everything into /usr/bin, which is OS territory

On many Linux distros, Python is pretty much part of the OS.
Since the early days of RedHat, Python has been part of the
base/minimum install since a lot of the required system
utilities were written in python.  In Redhat, the package
manger was originally written in Python, so Python had to be in
OS territory.

 (as has been decreed long ago by hier(7)), but rather use
 /usr/local/bin (all BSD Unix and derivatives) or /opt or
 whatever convention a particular operating system has.

In the Linux world, /usr/local/bin and /opt are for stuff
installed by the user, not stuff that is an integral, required
part of the OS distribution.

-- 
Grant

--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Grant Edwards
On 2008-05-02, Jeroen Ruigrok van der Werven [EMAIL PROTECTED] wrote:
 -On [20080502 07:51], Ben Finney ([EMAIL PROTECTED]) wrote:
To my mind, the Python interpreter installed by a package as
distributed with the OS *is* OS territory and belongs in /usr/bin/.

 That's the difference with a distribution, such as Linux, and full OSes ,
 such as BSDs or commercial Unix variants. They prefer to keep a pristine
 state for the OS vendor files

Python _is_ an OS vendor file in the Linux world.

 versus what the user can opt to install himself,

Traditionally, Python has not been optional.

 hence the /usr/bin - /usr/local/bin separation. Same for sbin,
 lib, and so on. It effectively guarantees you can nuke
 /usr/local without ill consequences for your OS.

That's the point. You _couldn't_ nuke Python and have your
system keep running.  That's why it was in /usr/bin.

-- 
Grant

--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread D'Arcy J.M. Cain
On Fri, 02 May 2008 16:26:51 +0200
Torsten Bronger [EMAIL PROTECTED] wrote:
  Certainly #! /usr/bin/python is fine if you never expect your
  software to run outside of your own little corner of the world but
  you asked why people prefer the env version and the answer is that
  we want to write software that runs everywhere that Python runs.
 
 Granted, but you must draw the line somewhere anyway.  I cannot

No one is talking about if statements here.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Torsten Bronger
Hallöchen!

D'Arcy J.M. Cain writes:

 On Fri, 02 May 2008 16:26:51 +0200
 Torsten Bronger [EMAIL PROTECTED] wrote:

 Certainly #! /usr/bin/python is fine if you never expect your
 software to run outside of your own little corner of the world
 but you asked why people prefer the env version and the answer
 is that we want to write software that runs everywhere that
 Python runs.
 
 Granted, but you must draw the line somewhere anyway.  I cannot

 No one is talking about if statements here.

Sorry to become laconical, but your reply was so, too:
http://en.wikipedia.org/wiki/Abstraction

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread D'Arcy J.M. Cain
On Sat, 03 May 2008 00:44:00 +1000
Ben Finney [EMAIL PROTECTED] wrote:
 D'Arcy J.M. Cain [EMAIL PROTECTED] writes:
  As someone else pointed out, not all the world is Linux.
 
 It's a good thing I've never implied such to be the case.

You haven't *said* it but you have definitely *implied* it.  Installing
Python in /usr/bin is not common.  It is very specific to your system.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread D'Arcy J.M. Cain
On Sat, 03 May 2008 00:43:02 +1000
Ben Finney [EMAIL PROTECTED] wrote:
 Roy Smith [EMAIL PROTECTED] writes:
  Have you ever shipped software to a customer?
 
 Yes, and all parties have been quite happy with the results.

When some of us talk about shipping software we aren't talking about a
20 line script delivered to our uncle's construction company office.  We
are talking about millions of lines of code in thousands of programs and
modules that has to run out of the box on whatever system the client
happens to run on.

  Customer: I can't install it there because insert whatever silly
  reason the customer has. If you can't make your product work
  without requiring me to install python in /usr/bin, I'm afraid I
  can't buy your product.
 
 At this point they have the simple option of running the program with
 'python /path/to/the/program'. It's certainly not a case of can't
 make the product work.

Simple for your 20 line single script.  Not so simple for my million
line, integrated system that has to work everywhere.

 It is, however, a case of can't automatically account for every local
 customisation sysadmins choose to make on their systems. Perfectly
 willing to work with them to get their specific environment working,
 but as a matter of simple economics it's not worth my time to attempt
 to make such corner cases work automatically.

If by corner case you mean some system that I don't personally run
then OK but to some of us your system is the corner case and we would
like our code to run there as well.

Real software has to deal with the fact that support costs money.
You may be able to deal with one or two clients that way but that does
not scale very well.

 If they've already chosen to install Python to some unpredictable
 location, they know what they're doing enough to invoke the program in
 a specific way to get it working.

Unpredictable to you.  Perfectly predictable on their system.

I do believe I am done with this thread.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Grant Edwards
On 2008-05-02, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote:
 On Sat, 03 May 2008 00:44:00 +1000
 Ben Finney [EMAIL PROTECTED] wrote:
 D'Arcy J.M. Cain [EMAIL PROTECTED] writes:
  As someone else pointed out, not all the world is Linux.
 
 It's a good thing I've never implied such to be the case.

 You haven't *said* it but you have definitely *implied* it.
 Installing Python in /usr/bin is not common.

It is common.  That's where it's installed by almost all Linux
distributions.

 It is very specific to your system.

Are you claiming that Linux is not a common Unix-like OS?

-- 
Grant

--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Yves Dorfsman

Thanks everybody, I didn't mean to start a flamewar...
I do get it now, it's whatever python is in the path, vs. the specific one 
you're pointing to.


Ben Finney wrote:



No, because it's quite common for the PATH variable to have
'/usr/local/bin' appear *before* both of '/bin' and '/usr/bin'.

If the system has a sysadmin-installed '/usr/local/bin/python'
installed as well as the OS-installed '/usr/bin/python', then the two
shebang options the OP raised will behave differently on such a
system. This seems to be quite the point of the discussion.



And I have to admit, I prefer specifying the version (full path) because I 
have run into too many problem when users have different PATHs and end up 
running different version of an interpreter.


Yves.
--
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Thorsten Kampe
* Ben Finney (Sat, 03 May 2008 00:37:45 +1000)
 Thorsten Kampe [EMAIL PROTECTED] writes:
  * Ben Finney (Fri, 02 May 2008 23:30:01 +1000)
   The OP was asking why people prefer on over the other. My answer
   is that I prefer specifying give me the default OS Python
   because anything not installed by the OS is to non-standardised
   for me to worry about.
   
   Others may prefer something different, but then they get to wear
   whatever problems occur as a result of that choice. I continue to
   be bemused by that preference, and nothing that I've seen so far
   in this thread illuminates the issue more.
  
  You're missing the point. Apart from the really dubious terms you
  use (OS installable package), using env in the first line has
  exactly the effect to use the default path of Python (which is the
  first entry in your path)
 
 No, because it's quite common for the PATH variable to have
 '/usr/local/bin' appear *before* both of '/bin' and '/usr/bin'.
 
 If the system has a sysadmin-installed '/usr/local/bin/python'
 installed as well as the OS-installed '/usr/bin/python', then the two
 shebang options the OP raised will behave differently on such a
 system. This seems to be quite the point of the discussion.

Again you're missing the point. If you or whoever installs Python (or 
another version of Python) to /usr/local/bin and puts this in the path 
to front (as it's often done) then /you/ want that Python to be the 
default one. It would just be silly to say no, I the developer want 
/usr/bin/python.

So in general #! env is better while in certain circumstance 
hardcoding the path to /usr/bin/python can be better.


Thorsten
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Carl Banks
On May 2, 11:07 am, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote:
 On Sat, 03 May 2008 00:43:02 +1000

 Ben Finney [EMAIL PROTECTED] wrote:
  Roy Smith [EMAIL PROTECTED] writes:
   Have you ever shipped software to a customer?

  Yes, and all parties have been quite happy with the results.

 When some of us talk about shipping software we aren't talking about a
 20 line script delivered to our uncle's construction company office.  We
 are talking about millions of lines of code in thousands of programs and
 modules that has to run out of the box on whatever system the client
 happens to run on.

If you're shipping a program that large you out to be packaging the
Python interpreter with it.

Frankly, this whole discussion is silly, as if it's some kind hard
thing to open the script with a text editor and modify the shbang
line.


Carl Banks



   Customer: I can't install it there because insert whatever silly
   reason the customer has. If you can't make your product work
   without requiring me to install python in /usr/bin, I'm afraid I
   can't buy your product.

  At this point they have the simple option of running the program with
  'python /path/to/the/program'. It's certainly not a case of can't
  make the product work.

 Simple for your 20 line single script.  Not so simple for my million
 line, integrated system that has to work everywhere.

  It is, however, a case of can't automatically account for every local
  customisation sysadmins choose to make on their systems. Perfectly
  willing to work with them to get their specific environment working,
  but as a matter of simple economics it's not worth my time to attempt
  to make such corner cases work automatically.

 If by corner case you mean some system that I don't personally run
 then OK but to some of us your system is the corner case and we would
 like our code to run there as well.

 Real software has to deal with the fact that support costs money.
 You may be able to deal with one or two clients that way but that does
 not scale very well.

  If they've already chosen to install Python to some unpredictable
  location, they know what they're doing enough to invoke the program in
  a specific way to get it working.

 Unpredictable to you.  Perfectly predictable on their system.

 I do believe I am done with this thread.

 --
 D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three 
 wolveshttp://www.druid.net/darcy/   |  and a sheep voting on
 +1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Erik Max Francis

Ben Finney wrote:


No, because it's quite common for the PATH variable to have
'/usr/local/bin' appear *before* both of '/bin' and '/usr/bin'.

If the system has a sysadmin-installed '/usr/local/bin/python'
installed as well as the OS-installed '/usr/bin/python', then the two
shebang options the OP raised will behave differently on such a
system. This seems to be quite the point of the discussion.


Yes, and that's the reason the env form is preferred.  If someone -- 
either the system administrator, or the user environment, or the person 
executing the program on the fly -- has changed the PATH, they did it 
for a reason.  If /usr/local/bin is in the PATH before /usr/bin, then 
that is a deliberate choice (whether system-wide or not) to prefer 
executables in /usr/local/bin to those in /usr/bin, and that is being 
done for a very conscious reason.  Which is why the PATH exists in the 
first place, and why invoking the script with env is preferable.



--
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
 San Jose, CA, USA  37 18 N 121 57 W  AIM, Y!M erikmaxfrancis
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Robert Kern

Yves Dorfsman wrote:

On UNIX, some people use
#!/usr/bin/env python

While other use
#!/usr/bin/python

Why is one preferred over the other one ?


Caveat: I've only read *most* of this thread, so maybe someone else has already 
made the following point.


It depends on the context. Ultimately, when your script is installed, it (almost 
certainly) should point to the precise Python executable the installer intends 
it to run on. One of the features of distutils is that it will *rewrite* 
#!/usr/bin/env python to use the exact executable that the installer used to 
execute the setup.py.


So *as a developer* I recommend writing your scripts with #!/usr/bin/env 
python. This lets distutils select the correct executable, and it lets your 
users play around with your scripts prior to installation without needing to 
rewrite the shebang line manually. I hate trying out someone's code just to find 
that that they hardcoded /usr/local/bin/python2.3. If you aren't using distutils 
to install for some reason, you might want to recommend that the installer 
change the shebang line in your installation instructions.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Ben Finney
D'Arcy J.M. Cain [EMAIL PROTECTED] writes:

 On Sat, 03 May 2008 00:43:02 +1000
 Ben Finney [EMAIL PROTECTED] wrote:
  Roy Smith [EMAIL PROTECTED] writes:
   Have you ever shipped software to a customer?
  
  Yes, and all parties have been quite happy with the results.
 
 When some of us talk about shipping software we aren't talking about
 a 20 line script delivered to our uncle's construction company
 office.

Nor was I. Thanks for the condescension and straw-man attacks, but...

 I do believe I am done with this thread.

That's a relief.

-- 
 \  “He that would make his own liberty secure must guard even |
  `\ his enemy from oppression.” —Thomas Paine |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-02 Thread Gabriel Genellina
En Fri, 02 May 2008 12:07:55 -0300, D'Arcy J.M. Cain [EMAIL PROTECTED]  
escribió:

On Sat, 03 May 2008 00:43:02 +1000
Ben Finney [EMAIL PROTECTED] wrote:

Roy Smith [EMAIL PROTECTED] writes:



 Have you ever shipped software to a customer?

Yes, and all parties have been quite happy with the results.


When some of us talk about shipping software we aren't talking about a
20 line script delivered to our uncle's construction company office.  We
are talking about millions of lines of code in thousands of programs and
modules that has to run out of the box on whatever system the client
happens to run on.
[...]
Simple for your 20 line single script.  Not so simple for my million
line, integrated system that has to work everywhere.


In that case you have a setup script, I presume. You use distutils or a  
better alternative, I presume. You use the scripts= argument to setup, or  
the install_scripts distutils command, I presume. The first line on your  
scripts starts with #! and contains the word python somewhere, I presume.  
Then, distutils will adjust that shebang line using the same python  
executable that was used to run the installation.
It doesn't matter whether the line read #!/usr/bin/python, #!/usr/bin/env  
python, #~/bin/python2.3 or just #!python: whatever Python was used to  
install your program, that will be written as the first line on the  
script, and consequentely that will be used to execute the script in the  
future. So the admin (or whoever installs the system) only has to make  
sure to use the right Python version from the right directory. That's all.  
Plain easy, isn't it?


I can't believe some angry responses in this thread - it's just a  
technical question, not about which is the best team in the [preferred  
sports here] National Championship...


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread J Sisson
The first method allows python to be installed in an alternate location
(i.e. /usr/local/bin).  env in this case is being used to launch python
from whatever location python is installed to.

I like to think of it as an abstraction of the python location to make it
multiplatform-friendly since not all Unix systems put python in /usr/bin.

On Fri, May 2, 2008 at 1:36 AM, Yves Dorfsman [EMAIL PROTECTED] wrote:

 On UNIX, some people use
 #!/usr/bin/env python

 While other use
 #!/usr/bin/python

 Why is one preferred over the other one ?

 Thanks.

 --
 Yves.
 http://www.SollerS.ca
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Computers are like air conditioners...
They quit working when you open Windows.
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread Ben Finney
Yves Dorfsman [EMAIL PROTECTED] writes:

 On UNIX, some people use
 #!/usr/bin/env python
 
 While other use
 #!/usr/bin/python

You haven't indicated your understanding of what the difference in
meaning is, so I'll explain it for those who might not know.

The shebang line (the initial line of the file beginning with #!)
takes advantage of OS kernels that determine how to execute a file
based on the first few bytes of the file. The shebang line tells the
kernel that this file should be executed by passing it as input to
a process started by another command.

The specified command takes the form of a fully-qualified file path,
and zero or one arguments to the program. That command is then
executed by the kernel, and the Python program file is passed as input
to the resulting process.

The difference between the two is thus what command is executed to
interpret the Python program.

* #! /usr/bin/env python will run the command /usr/bin/env python.
  The 'env(1)' manual page says its purpose is to run a program in a
  modified environment, but it also has the effect that the command
  is searched on the current PATH variable, and executed based on the
  first occurrence.

* #! /usr/bin/python will run the command /usr/bin/python, which
  is of course the system Python instance as installed by most OS
  packaging systems. That command is run, and the result is the Python
  interpreter.

 Why is one preferred over the other one ?

I've never clearly understood why people want to use #! /usr/bin/env
python, which is prone to finding a different Python from the one
installed by the operating system. I'd be interested to see what
responses are in favour of it, and what the reasoning is.

One possible reason is that the programmer is attempting to allow for
systems where Python has been installed, but not from an operating
system package.

I much prefer #! /usr/bin/python because I want my Python programs
to, by default, be run with the default Python, and depend on Python
being installed by the operating system's package manager. On systems
that use shebang lines and that actually have standardised filesystem
locations, the default Python is found at '/usr/bin/python'.

-- 
 \  Any sufficiently advanced bug is indistinguishable from a |
  `\  feature. —Rich Kulawiec |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread Roy Smith
In article [EMAIL PROTECTED],
 Ben Finney [EMAIL PROTECTED] wrote:

 I've never clearly understood why people want to use #! /usr/bin/env
 python, which is prone to finding a different Python from the one
 installed by the operating system. I'd be interested to see what
 responses are in favour of it, and what the reasoning is.
 
 One possible reason is that the programmer is attempting to allow for
 systems where Python has been installed, but not from an operating
 system package.

You've got it exactly.

I'm currently using Python to write unit tests as part of a build system.  
Many of our development boxes don't have python installed in /usr/bin (or 
perhaps at all).  And even if they did, we might want to use a different 
version of Python on different branches of the code.

We've got Python built for all our platforms and the binaries stored in our 
source control system.  When you check out a particular branch, you get the 
right version of Python for that branch.  By having the Python scripts 
start with #!/usr/bin/env python, I can select the version of Python I want 
just by changing the environment.

Then, of course, I recently ran across a machine where env was installed in 
/opt/gnu/bin instead of /usr/bin.  Sigh.  Sometimes you just can't win.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread D'Arcy J.M. Cain
On Fri, 02 May 2008 13:24:01 +1000
Ben Finney [EMAIL PROTECTED] wrote:
 I much prefer #! /usr/bin/python because I want my Python programs
 to, by default, be run with the default Python, and depend on Python
 being installed by the operating system's package manager. On systems
 that use shebang lines and that actually have standardised filesystem
 locations, the default Python is found at '/usr/bin/python'.

You have lived a sheltered life.  Not every packaging system puts the
executible in /usr/bin.  Many systems use /usr/local/bin.  NetBSD
uses /usr/pkg/bin but allows you to define your own pkg root.
Using /usr/bin/env allows your code to run on all these systems.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread Jeroen Ruigrok van der Werven
-On [20080502 05:26], Ben Finney ([EMAIL PROTECTED]) wrote:
I've never clearly understood why people want to use #! /usr/bin/env
python, which is prone to finding a different Python from the one
installed by the operating system. I'd be interested to see what
responses are in favour of it, and what the reasoning is.

Simple, some systems are not as peculiar as a lot of Linux boxes which
chug everything into /usr/bin, which is OS territory (as has been decreed
long ago by hier(7)), but rather use /usr/local/bin (all BSD Unix and
derivatives) or /opt or whatever convention a particular operating system
has.

And prone to find the wrong Python, it all depends upon proper $PATH
administration.

As such, your script with #!/usr/bin/python is as bad as an ash shell script
with #!/bin/bash. #!/usr/bin/env python is more cross-OS friendly, there's
more than just Linux you know.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
I dream of Love as Time runs through my hand...
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread Tim Roberts
Yves Dorfsman [EMAIL PROTECTED] wrote:

On UNIX, some people use
#!/usr/bin/env python

While other use
#!/usr/bin/python

Why is one preferred over the other one ?

The /usr/bin/env solution finds the Python interpreter anywhere on the
PATH, whether it be /usr/bin or /usr/local/bin, or whatever.  With
/usr/bin/python, it MUST be in /usr/bin.

Way back when, Python wasn't included in Linux distributions by default, so
it was difficult to predict where it would be.  /usr/bin/env, on the other
hand, is well-established at that location.

These days, since Python is nearly ubiquitous, I suspect it is not so
important.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread Ben Finney
Jeroen Ruigrok van der Werven [EMAIL PROTECTED] writes:

 -On [20080502 05:26], Ben Finney ([EMAIL PROTECTED]) wrote:
 I've never clearly understood why people want to use #!
 /usr/bin/env python, which is prone to finding a different Python
 from the one installed by the operating system. I'd be interested
 to see what responses are in favour of it, and what the reasoning
 is.
 
 Simple, some systems are not as peculiar as a lot of Linux boxes
 which chug everything into /usr/bin, which is OS territory (as has
 been decreed long ago by hier(7)), but rather use /usr/local/bin
 (all BSD Unix and derivatives) or /opt or whatever convention a
 particular operating system has.

To my mind, the Python interpreter installed by a package as
distributed with the OS *is* OS territory and belongs in /usr/bin/.

 As such, your script with #!/usr/bin/python is as bad as an ash
 shell script with #!/bin/bash.

Clearly if the program is written to be interpreted by the Ash shell,
it should not declare Bash as the interpreter.

I don't see how declaring Python as the interpreter for a Python
program is supposed to be as bad as that.

-- 
 \ Don't be afraid of missing opportunities. Behind every failure |
  `\  is an opportunity somebody wishes they had missed.  -- Jane |
_o__)  Wagner, via Lily Tomlin |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-01 Thread Ben Finney
D'Arcy J.M. Cain [EMAIL PROTECTED] writes:

 On Fri, 02 May 2008 13:24:01 +1000
 Ben Finney [EMAIL PROTECTED] wrote:
  I much prefer #! /usr/bin/python because I want my Python
  programs to, by default, be run with the default Python, and
  depend on Python being installed by the operating system's package
  manager. On systems that use shebang lines and that actually have
  standardised filesystem locations, the default Python is found at
  '/usr/bin/python'.
 
 You have lived a sheltered life.  Not every packaging system puts the
 executible in /usr/bin.  Many systems use /usr/local/bin.

They use that for the operating-system-installed default Python
interpreter? Colour me incredulous.

-- 
 \   “[The RIAA] have the patience to keep stomping. They’re |
  `\playing whack-a-mole with an infinite supply of tokens.” |
_o__)  —kennon, http://kuro5hin.org/ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list