python_selectを使って複数バージョンのPythonを使い分ける

自前のサーバ使うときはPython2.7なんですけど、GAE使うときはPython2.5なので、両方の環境が必要になります。そういう時はpython_selectが便利。今時はVirtualEnv使うのがトレンドなのかもしれないけど。python_selectのインストールは簡単です。

sudo port install python_select

で、

port select –list python

これでインストールされているPythonの一覧が出てきます。ハセテツの環境では以下のようになります。

Available versions for python:

none
python25 (active)
python25-apple
python26-apple
python27

これはPython2.5が現時点では選択されているということです。

sudo port select –set python python27

これでPython2.7が選択され、使用できる様になります。

Selecting ‘python27’ for ‘python’ succeeded. ‘python27’ is now active.

簡単簡単、便利便利。Windowsの場合、Path通し直すしかないのかな。