views:

521

answers:

5

I downloaded a package installer for Python 2.6.1, but when I use the python command in terminal (bash) Apple's shipped 2.3.5 version loads up. How can I get 2.6.1 to load up instead?

+4  A: 

You probably need to edit your ~/.profile file. It contains your PATH variable, which tells the command line where to find things. You can do so like this:

export PATH=/path/to/new/python:$PATH

That puts your new path as the first place to look.

Nerdling
+4  A: 

I am running Leopard, 10.5.5. The python binary, /usr/bin/python, is merely a symlink to the actual binary in the version specific Python folder. For example:

$ ls -l /usr/bin/python
lrwxr-xr-x  1 root  wheel  72 Aug 31  2008 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python

And a look inside that /Versions folder reveals this:

$ ls -l /System/Library/Frameworks/Python.framework/Versions/
total 8
drwxr-xr-x   7 root  wheel  238 Aug 31  2008 2.3
drwxr-xr-x  13 root  wheel  442 Nov 22 20:40 2.5
lrwxr-xr-x   1 root  wheel    3 Aug 31  2008 Current -> 2.5

With the help of the ln command to create symlinks, you will be able to set the python in your path to point to the version of python you want to use.

ayaz
so something like: ln -s /usr/bin/python /Library/Frameworks/Python.framework/Versions/2.6/bin/python ?
Ronald: Swap the arguments. The target, '/usr/bin/python', should come last. Do read the man page for ln if it isn't clear.
ayaz
I swapped the arguments and ran the command, which resulted in: "ln: /usr/bin/python: File exists"
then, rm /usr/bin/pythonand ln -s /Library/Frameworks/Python.framework/Versions/2.6/bin/python /usr/bin/python
Martin
Yes, you'll have to remove /usr/bin/python first before running the ln command. But before you remove it, please make sure /usr/bin/python is just a symlink like on Leopard and not a binary file instead.
ayaz
Success my friends! Thanks a lot!
Please don't overwrite the system python, apps expect it to never change and may break. It's much better to fix your PATH variable so your new python comes first.
vasi
+1  A: 

Apart of making symlink or putting /usr/local at the front of PATH environment variable, you can try to make use of MacPorts. Installing Python from ports takes bit longer (it has to be compiled from source), but ports provide you with the most reliable way of installing PIL into your Python (apart of issuing sudo apt-get install python-imaging in Ubuntu...).

zgoda
A: 

you could try typing python2.6 instead of python. This may require you to set up your PATH "correctly"

I'd recommend that if you'd like to do single machine python development on your Mac to use MacPorts. It gives you the control (since by default, everything gets installed in /opt/local) over which version of python you use (assuming you can modify your $PATH envariable). It also makes it simple and easy to have installed multiple versions of python simultaneously, along with their optional binary packages.

The MacPorts path to python2.6 on my system is:

/opt/local/bin/python2.6

if you use something like #!/usr/bin/env python2.6, you may need to modify your PATH environment variable to include MacPorts (or your other python2.6 version) in order to pull in the desired version of python when the script runs

Here's an example command which assuming BASH shell, and the location to my MacPorts bin directory:

export PATH=/opt/local/bin:$PATH
popcnt
A: 

As for putting environment variables in your profiles... If you're on Leopard, try putting them in /etc/paths.d

see here for more...

Abizern