default python os x

U

Uwe Rangs

Hello,

how can I change the default version of python with os x 10.7.

Thanks,
Uwe
 
U

Uwe Rangs

My workflow at the moment is to set a link:
mv python python_old
ln -s /usr/local/bin/python3.2 python

But is this a good idea?

-- Uwe
 
S

Steven D'Aprano

My workflow at the moment is to set a link: mv python python_old
ln -s /usr/local/bin/python3.2 python

But is this a good idea?


You should never change the system Python, since that runs the risk of
breaking system tools that expect a particular version. If there are any
system tools that run "python", they may break.

Instead, set a personal alias. For example, in my ~/.bashrc
file, I have the following:


export PYTHONPATH="/home/steve/python/:/home/steve/python/utilities"
export PYTHONSTARTUP=/home/steve/python/utilities/startup.py
alias python=python2.7
alias python3=python3.3
alias python1.5='env -u PYTHONSTARTUP python1.5'
alias python2.0='env -u PYTHONSTARTUP python2.0'
alias python2.1='env -u PYTHONSTARTUP python2.1'
alias python2.2='env -u PYTHONSTARTUP python2.2'
alias python2.3='env -u PYTHONSTARTUP python2.3'
alias python3.4="env -u PYTHONPATH ~/python/cpython/python"


So, for me, and me alone, typing "python" refers to Python 2.7 instead of
the system Python, which happens to be 2.4 on my server and 2.6 on my
laptop. "python1.5" etc unsets the startup file environment variable,
since my startup file assumes 2.4 or better. "python3.4" points to a
local copy in my home directory. Otherwise, python3.3, python3.2, etc.
work as expected.
 
U

Uwe Rangs

Ah, I see. Thank you!

You should never change the system Python, since that runs the risk of
breaking system tools that expect a particular version. If there are any
system tools that run "python", they may break.

Instead, set a personal alias. For example, in my ~/.bashrc
file, I have the following:


export PYTHONPATH="/home/steve/python/:/home/steve/python/utilities"
export PYTHONSTARTUP=/home/steve/python/utilities/startup.py
alias python=python2.7
alias python3=python3.3
alias python1.5='env -u PYTHONSTARTUP python1.5'
alias python2.0='env -u PYTHONSTARTUP python2.0'
alias python2.1='env -u PYTHONSTARTUP python2.1'
alias python2.2='env -u PYTHONSTARTUP python2.2'
alias python2.3='env -u PYTHONSTARTUP python2.3'
alias python3.4="env -u PYTHONPATH ~/python/cpython/python"


So, for me, and me alone, typing "python" refers to Python 2.7 instead of
the system Python, which happens to be 2.4 on my server and 2.6 on my
laptop. "python1.5" etc unsets the startup file environment variable,
since my startup file assumes 2.4 or better. "python3.4" points to a
local copy in my home directory. Otherwise, python3.3, python3.2, etc.
work as expected.
 
C

Cameron Simpson

| Ah, I see. Thank you!

Please don't top post. Thanks.

| On 2013-08-20 05:39:56 +0000, Steven D'Aprano said:
| >alias python1.5='env -u PYTHONSTARTUP python1.5'

I should point out that -u is a GNU env feature. It is not portable,
and in particular OSX "env" does not have it.

A shell function can do the same though:

py20() {
( unset PYTHONSTARTUP
exec python2.0 ${1+"$@"}
)
}

I've said py20 instead of python2.0 primarily because bash is a
bit... picky about function names and rejected the ".".

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top