Bob Ippolito wrote:
On Apr 22, 2005, at 4:38 AM, Yair Benita wrote:
If it co-exist how do I control which one is used when simply typing
/usr/bin/python at the command line?

NEVER EVER change anything in /usr (except /usr/local) or /System. DO NOT EVER DO THAT. BAD.

I think the OP was not proposing that, but rather was trying to figure out how to run the different pythons. So to give a little more info:


Apple puts their python (2.3.0) in:

/usr/bin/python

When you install 2.4.* (and any python that isn't supplied by Apple, hopefully), it will not put it in /usr/bin . It should put it in /usr/local/bin/python (or maybe /opt/... or /sw/....)

So, after installing python2.4, you'll have two "python" executables, but they won't be in the same place. This is where PATH comes in.

try typing:

$PATH

at the command line. It will give you a colon separated list of paths that bash looks for executables in. It looks in the order given, so if you have /usr/local/bin and /usr/bin in your path, and there is a python in each one, it will find the one in the path that comes first in the list. Many folks recommend manipulating your PATH as the way to set the default python. For instance, if you put:

export PATH=/usr/local/bin:$PATH

in your .profile file (there are other placed to put it as well, search the web for suggestions), then bash will find the new version first, and run that when you type "python".

However, the most common way to specify python in a script is:

#!/usr/bin/env python

This lets the shell figure out where python is, rather than specifying the exact path. This is nice, and makes your scripts more portable, but it means that if you manipulate PATH, you'll change what it found, and old scripts that depend on the old python will stop working (this was an infamous problem with RedHat Linux a while back, I don't know if they've fixed it.)

Because of this, I don't recommend altering your default python in that way. I put:

export $PATH:PATH=/usr/local/bin

in my .profile, so that the system one is found first. By the way, this doesn't just affect python, it affects every command line program. I don't want to accidentally change the default anything.

Want I do instead is specify the version I want at the command line or in the script:

$ python2.4

or

#!/usr/bin/env python2.4

(or python2.3, of course)

There should be a /usr/local/bin/python2.4 after you install 2.4. If not the distribution is broken, but you can fix it easily with a link.

This way, after you upgrade, anything you write now can use python2.4, and anything you wrote before can still use 2.3.

I hope that helped.

You know, this is enough of FAQ, it must be in the Wiki by now. If not, I guess I should add it (or perhaps the OP could put this in)

-Chris


-- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception

[EMAIL PROTECTED]
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to