CentOS5.5にPython2.7&Mercurialをインストールしようとしたら色々とハマったので
先日、SCMBootCamp*1に参加させて頂き、Mercurialの魅力を体験できたので、業務でも使えるように自宅のCentOS5.5サーバーにもインストールしてみました。Pythonも初心者だったので、その時に色々と手間がかかったので備忘録を残しておきます。
まずはPython2.7のインストール
CentOS5.5に標準でインストールされているPythonのバージョンを確認したところ、
Python 2.4.3
でしたので、こちらのブログを参考に、最新版のPythonを公式ダウンロードページから取得し、2系で最新の2.7をインストールしました。
cd /usr/local/src/ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz tar xzvf Python-2.7.2.tgz cd Python-2.7.2 ./configure --with-threads --enable-shared --prefix=/usr/ make make install
デフォルトだとインストール先が/usr/local/以下なのですが、pythonコマンドでデフォルトで起動するPythonを2.7にしたかったので、--prefix=/usr/ と指定。(この指定が後の問題を引き起こすとはまだ知らない)
easy_installを使えるようにしておくと楽だと聞いたので、pypiにてsetuptoolsもインストール。
cd /usr/local/src wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e tar xzvf setputools-0.6c11.tar.gz cd setuptools-0.6c11 python setup.py build python setup.py install
Mercurialをインストールで問題発生
よし、easy_installを使えるようになったぞ!ということで、easy_install mercurial にてインストールを試みたのですがここで問題が発生。
なんと、pythonに正しくbz2モジュールが組み込まれていないというエラーが発生し、インストールができない。
error: Setup script exited with Couldn't import standard bz2 (incomplete Python install).
"yum install bzip2-devle"の実行でもエラー発生
以下のようなエラーが発生しました。
There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version of Python, which is: 2.7.2 (default, Aug 13 2011, 20:56:43) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] If you cannot solve this problem yourself, please go to the yum faq at: http://wiki.linux.duke.edu/YumFaq
きっとPythonのアップグレードが関係しているのだろうなー、と思い、yumのソースを見てみたら、yumはPythonスクリプトだったというわけで・・・(常識ですかね・・・)。
$ vi /usr/bin/yum #!/usr/bin/python import sys try: import yum except ImportError: print >> sys.stderr, """\ There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: %s Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version of Python, which is: %s If you cannot solve this problem yourself, please go to the yum faq at: http://wiki.linux.duke.edu/YumFaq """ % (sys.exc_value, sys.version) sys.exit(1) sys.path.insert(0, '/usr/share/yum-cli') try: import yummain yummain.user_main(sys.argv[1:], exit_code=True) except KeyboardInterrupt, e: print >> sys.stderr, "\n\nExiting on user cancel." sys.exit(1)
おお、そうか!もしや先頭の”#!/usr/bin/python”の部分をpython2.4に向けてやれば良いのでは?ということで、先頭を"#!/usr/bin/python2.4"に書き換えてみたところ、無事yumが動くようになりました(`・ω・´)
教訓
参考ブログでも書いてありましたように、やはりpython2.7を再度インストールするハメになり、我が家のおんぼろサーバー機では再度コンパイルするのに結構な時間がかってしまいました。
今回の教訓としては。