views:

88

answers:

3

Hi guys, i'm new to the Mac OS X world so i have to ask you this.

I have the default python 2.6.1 installed as /usr/bin/python and the 3.1.2 as /usr/local/bin/python3.1 . Considering that i use only 3.x syntax, is it safe to replace the default interpreter (2.6) with the 3.1 one (python-config included) using symlinks (and removing old python binary), or is the system based on the old version for some purpose i don't know?

Thanks :)

+1  A: 

Don't replace / remove any binaries unless you are in dire need for storage. In that case too, the mileage is very little in removing them.

You can simply make 3.1 as default with :

defaults write com.apple.versioner.python Version 3.1

There are other ways to ensure that you use 3.1 by default, I have not used them though.

export VERSIONER_PYTHON_VERSION=3.1
pyfunc
Yes but i need the "python" command to execute python3.1 ... i tried both your solutions and none of them (obviously IMHO) changed the /usr/bin/python binary.
Simone Margaritelli
The `defaults` trick only works in 10.6 and, AFAICT, only for the Apple-supplied Pythons 2.5 and 2.6 in /usr/bin. (Yes, the man page suggests it works for 3.0 which I'm guessing was planned at one point to be releases with 10.6 but wasn't). And, again, it would be a really bad idea to make `python` refer to a Python 3 instance at this point in the transition. `python3` should be used as the generic reference.
Ned Deily
+5  A: 

If you're only using Python 3, start your scripts with:

#! /usr/bin/env python3.1

And you'll be using the right version, without doinking the system about.

edit: BTW this idea is suggested by the Python docs. Each script will be running the version of Python they depend on. Since Python 3 is not backward compatible, it seems dangerous to be replacing the Python executable with one that will break scripts other utilities may rely on.

Graham Perks
A better option would be to use `python3` instead of `python3.1`. Then when python 3.2, 3.3, etc come out and are installed, you won't have to go back and remember to change this and other scripts.
ma3
+1  A: 

You can not safely replace the system supplied python. (Will find a reference for this shortly). Update... I've googled around a bit, and can not find a mac-specific reference for you... but some recent python versions are not backwards compatible... Many scripts made dependent on an older version of python will not run on an upgraded python. OSX Comes with python pre-installed because it has dependencies on it.

Try using VirtualEnv instead.

Update: Just came across python-select from macports which may solve your problem.

Good Luck!

Eric
In general, MacPorts `python_select` only works for MacPorts-installed Pythons although it does special case the default Apple-supplied Python in /usr/bin (2.5 for 10.5 and 2.6 for 10.6). And using just python_select for Python framework installs is generally not sufficient anyway; you need to be careful to include the default framework bin on your PATH to execute scripts installed for that Python instance (assuming you haven't used another Distutils installation scheme like --user).
Ned Deily