default python os x

Steven D'Aprano steve at pearwood.info
Tue Aug 20 01:39:56 EDT 2013


On Mon, 19 Aug 2013 22:24:46 +0200, Uwe Rangs wrote:

> 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.


-- 
Steven



More information about the Python-list mailing list