環境
CentOS release 6.8
インストールするもの
- pyenv
- pip
注意
CentOSのyumはプレインストールされているヴァージョンのPythonでしか動かないみたいです。なので、最新版のPythonをインストールしたらシステムがbreakしちゃうかもしれないのでしない方がいいとのことです。そこで、/usr/local 下にPythonをインストールするという裏技を使うそうです。イカの手順はHow to install the latest version of Python on CentOSに書いてある手順そのままです。
手順
development toolsをダウンロードしなきゃいけないそうです
# Compilers and related tools:
yum groupinstall -y "development tools"
# Libraries needed during compilation to enable all features of Python:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
# If you are on a clean "minimal" install of CentOS you also need the wget tool:
yum install -y wget
次にPython2と3のソースコードをwgetしてきてそれをコンパイルします
# Python 2.7.13:
wget http://python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
tar xf Python-2.7.13.tar.xz
cd Python-2.7.13
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
# Python 3.6.0:
wget http://python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xf Python-3.6.0.tar.xz
cd Python-3.6.0
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
何をしてるのかは分かりませんがこれも一応やっておきました
strip /usr/local/lib/libpython2.7.so.1.0
strip /usr/local/lib/libpython3.6m.so.1.0
続いてpipのインストールですが、そのためのPythonスクリプトがあるようでwgetしてきてそれを実行します。
# First get the script:
wget https://bootstrap.pypa.io/get-pip.py
# Then execute it using Python 2.7 and/or Python 3.6:
python2.7 get-pip.py
python3.6 get-pip.py
これでpip install
が使えますね!やったー!