しまてく

学んだ技術を書きためるブログ

さくらインターネットにpythonを再インストール

あれやこれやといろいろ弄っているうちにだんだん環境がよごれてきたので
いったん全部消してからpythonを再インストールするとします。

まずはお掃除

%find /home/cimadai -name "*python*"

でそれらしいものがリストアップされるので、こいつらを消す。
コマンドは↓

%rm -rf dir_name
    • [r]はディレクトリごと削除
    • [f]は確認なしで強制的に削除

pythonのインストール。

といってもさくらインターネットにはすでにpythonが入っています。
が、いろいろと自分でやりたいお年頃なので、virtual-pythonという
ものを利用して一から環境を作っていきたいと思います。
#今回は/home/cimadai/local/python/以下にインストール。

まずvirtual-pythonのインストール
%mkdir ~/local/python
%cd ~/local/src/
%wget http://peak.telecommunity.com/dist/virtual-python.py
%python virtual-python.py --prefix=/home/cimadai/python
    • インストール先のディレクトリを作成
    • 適当な場所にvirtual-pythonをDL
    • インストール先を指定してvirtual-pythonをインストール
環境変数の編集 ~/.cshrcファイルを修正
setenv PATH $HOME/local/python/bin
setenv PYTHONPATH $HOME/local/python

exitでいったんSSHを抜けてログインしなおす。

virtual-pythonが入った事を確認
%which python
/home/cimadai/local/python/bin/python

となることが確認できればココまでOK。

easy_installをインストール

これがないpythonが許されるのは(ry

とりあえず実行してみる。
%cd ~/local/src/
%wget http://peak.telecommunity.com/dist/ez_setup.py
%python ez_setup.py
むぅ。。なんかエラーだって言われた。
Downloading http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c8-py2.4.egg
TEST FAILED: /home/cimadai/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /home/cimadai/

and your PYTHONPATH environment variable currently contains:

    '/home/cimadai/local/python'

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python and want to use the package(s) you are installing.)

* You can set up the installation directory to support ".pth" files by
  using one of the approaches described here:

  http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations

Please make the appropriate changes for your system and try again.

どうやら以下の内容のファイルを作成するといいらしい。

[install]
install_lib = $HOME/local/python/lib
install_scripts = $HOME/local/python/bin

~/.pydistuils.cfg に保存。

さらに環境変数も追加
~/.cshrc
setenv PYTHONPATH $HOME/local/python:$HOME/local/python/lib
で、リトライ
%python ez_setup.py
Downloading http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c8-py2.4.egg
Creating /home/cimadai/local/python/lib/site.py
Processing setuptools-0.6c8-py2.4.egg
creating /home/cimadai/local/python/lib/setuptools-0.6c8-py2.4.egg
Extracting setuptools-0.6c8-py2.4.egg to /home/cimadai/local/python/lib
Adding setuptools 0.6c8 to easy-install.pth file
Installing easy_install script to /home/cimadai/local/python/bin
Installing easy_install-2.4 script to /home/cimadai/local/python/bin

Installed /home/cimadai/local/python/lib/setuptools-0.6c8-py2.4.egg
Processing dependencies for setuptools==0.6c8
Finished processing dependencies for setuptools==0.6c8

おお、成功したっぽい。

これで今日からeasy_installしまくりのステキなpython環境☆

今回参考にしたサイト