Python 起動の設定

新しいバージョンをインストールした時にいつもどうしたら良いのか迷うのがここ。システムの色々が古いバージョンに依存してそうで、新しいバージョンにすると動かなくなっちゃうんじゃないか?って。安易に /usr/bin/python を /usr/local/bin/python にリンクしちゃってもダメだろうし…。
というわけで、まずは /usr/local/bin をパスへ加える。
これは .bash_profile で。

[paraches@centos ~]$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/bin

export PATH
[paraches@centos ~]$ 

で、alias で python を python2.6 にする。
これは .bashrc で。

[paraches@centos ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific aliases and functions
alias python='python2.6'
[paraches@centos ~]$ 

これで、python と入力すると、python2.6 になって /usr/local/bin の python2.6 が起動する。

[paraches@centos ~]$ python
Python 2.6.6 (r266:84292, Sep 25 2010, 17:37:19) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[paraches@centos ~]$ 

とりあえずはここまで。