views:

735

answers:

2

Hi,

I would like to try out the Google App Engine Python environment, which the docs say runs 2.5.2. As I use OS X Leopard, I have Python 2.5.1 installed, but would like the latest 2.5.x version installed (not 2.6 or 3.0). It seems the latest version is 2.5.4

So, I went to here:

http://wiki.python.org/moin/MacPython/Leopard

and stopped because I am worried installing the latest version might mess with the standard install. I really just want one version installed.

So my questions are how do I safely install the latest 2.5.x? Is it possible to fully replace the built in version, and if so would that hurt any Mac tools?

Cheers, Shane

+3  A: 

Your current python is in /System/Library/Frameworks/Python.framework/.

If you install MacPython, it will go into /Library/Frameworks/Python.framework/. The installer will modify your $PATH (environment variable) so that typing python at the command line will run the version it installs.

You can easily get back the old version by modifying the path again.

You will have to reinstall any third-party modules you are using. This is because third-party modules go into Python.framework/Versions/Current/lib/python2.5/site-packages/ for the version you're running.

Since you're not modifying the system version, you aren't in danger of affecting any Apple system tools that rely on it.

(in fact, arguably it is safer to install MacPython from the start, and never touch the Apple-supplied version. See here for a similar situation involving Perl, where Apple updated the version of Perl in /System and broke a lot of people's setups)

You may also be interested in virtualenv.

John Fouhy
Thank you for your response. I had a look at my current install, and I have "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/", but it doesn't contain a "site-packages" folder. Does this mean I don't have any installed packages?If so, I looks like I can just go ahead and install.p.s. 'virtualenv' looks very interesting, but I really just want the latest 2.5 version, so it might be overkill.
Shane
Uh, it may do. I'm not certain. I'm running Tiger (which ships with py2.3) and I have a `site-packages` dir in `/System` (which is basically empty). If you haven't installed any then you shouldn't encounter any problems.
John Fouhy
Site packages for the Apple-supplied Python (/System/Library/...) are installed into /Library/Python/x.x/. Site packages for python.org installers (MacPython) get installed directly into the expected location within the framework at /Library/Frameworks/Python.framework/Versions/n.n...
Ned Deily
+5  A: 

You can install python on your Mac, and it won't mess with the default installation. However, I strongly recommend that you use MacPorts to install Python, since that will make it much easier for you to install Python libraries and packages further down the road. Additionally, if you try to install a program or library with MacPorts that depends on Python, MacPorts will download a copy of Python, even if you have MacPython installed, so you might end up with redundant copies of Python if you install MacPython but then choose to use MacPorts at a later date. To install Python with MacPorts, download and install MacPorts, then type:

sudo port install python25 python_select
sudo python_select python25

Run the following command to view all the MacPorts packages for Python:

port list | grep py25-

You can install any of the packages on the list by simply typing:

sudo port install packagename

In the above, replace packagename with the name of the package. On my first install I always run

sudo port install py25-setuptools

[ NOTE: These commands need to be run from the Terminal -- Applications > Utilities > Terminal.app ]

Michael Aaron Safyan
I personally use python 2.6 (you can use "py26" and "python26" in place of "py25" and "python25"), however the question asked for 2.5, so that's how you would do it. Does anything run on 2.5 that no longer runs on 2.6?
Michael Aaron Safyan
Also, switching between versions of Python with MacPorts is much easier than with MacPython; all you need to do is run "python_select" with the version you prefer, and "python_select -l" to list all installed versions.
Michael Aaron Safyan
Interesting. How does the system choose which version of python is used form a terminal session? Does the "sudo port install packagename" modify $PATH? Also, where do the files get install to?
Shane
I went ahead and took your advice! It took a while to download and compile everything, but now I am up to date. It feels very Liunx-y, which is nice. Cheers. :)
Shane
I'm not sure if python_select modifies your $PATH, but IIRC you can very simply switch between python installations by changing the targets of a couple of symbolic links (have a look in /usr/bin).
Matt Ball
The "python_select" command does not modify your path. When you install MacPorts, it places "/opt/local/bin" in your PATH. When you install the "python25", "python26", or "python30" packages, they create the binaries "python2.6", "python2.6", and "python3.0" in "/opt/local/bin", but do not also create a binary named "python" in "/opt/local/bin". What "python_select" does is create a symbolic link named "python" in "/opt/local/bin" that points to the binary of the python installation that you specify.
Michael Aaron Safyan
The "sudo port install packagename" does not modify your PATH. Your PATH is only modified once, when you install MacPorts (it addes "/opt/local/bin"). When you install a package beginning with "py25-", "py26-", or "py30-", it ends up in the site-packages folder for the respective python installation.
Michael Aaron Safyan
MacPorts installs everything under "/opt/local" (MacPorts uses "/opt/local" instead of "/usr/local" to avoid interference with any source packages which you have manually installed).
Michael Aaron Safyan