pyenvでPython3をインストール
Fedora20のPythonの標準バージョンは2.7.5。いい加減そろそろ標準をバージョン3系にしてほしい!Google App Engineといい、Pythonがいまひとつメジャーになり切れない理由のひとつはバージョン2系が標準として残っているからじゃないかな...。
というボヤキはさておき。
ひとつのシステムで複数バージョンのPythonを使いたいとき、今の私の頭の中にはpyenvを使うことしか考えられない。そこでpyenvを使ってPython3をインストールする。2014/07/23現在、Python3系の最新バージョンは3.4.1なので今回3.4.1を選択する。
pyenvのインストール
pyenvはgitを必要とするが、Fedoraインストール時にDevelopment Tools一式をインストールしてあれば、gitは入っている。
$ git --version git version 1.9.3 $ cd $ git clone git://github.com/yyuu/pyenv.git .pyenv Cloning into '.pyenv'... remote: Reusing existing pack: 7388, done. remote: Total 7388 (delta 0), reused 0 (delta 0) Receiving objects: 100% (7388/7388), 1.24 MiB | 641.00 KiB/s, done. Resolving deltas: 100% (5501/5501), done. Checking connectivity... done. $ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc $ cat .bashrc # .bashrc (略) export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" $ source .bashrc $ pyenv versions * system (set by /home/xxxxxxxx/.pyenv/version) ← xxxxxxxxはユーザー名 $
無事pyenvがインストールできた。
Python3.4.1のインストール
次にPython3.4.1のインストール。pyenvで簡単にインストールできると思っていたが、ライブラリーが足りないとエラーが出た。
$ pyenv install 3.4.1 Downloading Python-3.4.1.tgz... -> http://yyuu.github.io/pythons/8d007e3ef80b128a292be101201e75dec5480e5632e994771e7c231d17720b66 Installing Python-3.4.1... WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python readline extension was not compiled. Missing the GNU readline lib? ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? Please consult to the Wiki page to fix the problem. https://github.com/yyuu/pyenv/wiki/Common-build-problems BUILD FAILED Inspect or clean up the working tree at /tmp/python-build.20140723091225.2995 Results logged to /tmp/python-build.20140723091225.2995.log Last 10 log lines: (cd /home/xxxxxxxx/.pyenv/versions/3.4.1/share/man/man1; ln -s python3.4.1 python3.1) if test "xupgrade" != "xno" ; then \ case upgrade in \ upgrade) ensurepip="--upgrade" ;; \ install|*) ensurepip="" ;; \ esac; \ ./python -E -m ensurepip \ $ensurepip --root=/ ; \ fi Ignoring ensurepip failure: pip 1.5.6 requires SSL/TLS $
足りないのはbz2, readline, sslらしい。pyenvを調べるとこのへんに対策が書かれていたので、それに従いyumでそれらをインストールする。openssl-develを忘れずに!
$ sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite3 sqlite-devel openssl-devel (略) Complete! $
再度pyenvで3.4.1をインストールする。
$ pyenv install 3.4.1 Downloading Python-3.4.1.tgz... -> http://yyuu.github.io/pythons/8d007e3ef80b128a292be101201e75dec5480e5632e994771e7c231d17720b66 Installing Python-3.4.1... Installed Python-3.4.1 to /home/xxxxxxxx/.pyenv/versions/3.4.1 $ pyenv global 3.4.1 $ pyenv rehash $ pyenv versions system * 3.4.1 (set by /home/xxxxxxxx/.pyenv/version) $
Python3.4.1が無事インストールできた。