LoginSignup
205

More than 3 years have passed since last update.

CentOS に Python2.7, Python3を入れたメモ

Last updated at Posted at 2014-02-03

CentOS6.5の標準ではPython2.6が、CentOS7.2ではPython2.7が入っており色々と不都合があるので、新バージョンかつよく使うバージョンをインストールする。

なおインストール先は /opt/local とする。

追記

2020/01/10 追記:いい加減 Python3 を使いましょう。

Developer Tools をインストール

# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

Python 2.7, 3.6 install

まずダウンロードをしてきて、それらをインストールする。

curl -O https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
curl -O https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar zxf Python-3.6.6.tgz 
tar zxf Python-2.7.6.tgz 

Python2.7 のインストール

cd Python-2.7.6
./configure --prefix=/opt/local
make && make altinstall

Python3.6 のインストール

cd Python-3.6.6
./configure --prefix=/opt/local
make && make altinstall

Easy_install をインストールさせる

(2015/07/19: distribute のリンク先変更。 Thanks @mtomoaki_96kg さん :thumbsup: )

curl -O https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz
tar xzf distribute-0.6.49.tar.gz
cd distribute-0.6.49
/opt/local/bin/python2.7 ./distribute_setup.py 
/opt/local/bin/python3.3 ./distribute_setup.py 

2015/07/19 追記:distribute/setuptools をインストールしなくてもPIPはインストールできるようになっていますので、このステップは省略しても問題無いです。というより、pipでpip install distributeとコマンドを実行すればインストールできます。

see: https://pypi.python.org/pypi/distribute/0.6.49

PIP をインストール

(2014/09/27 追記)
(2015/04/22 raw.github.com から raw.githubusercontent.com へ変更)
(2015/07/19 githubから pypa のリンクへ変更 see: https://pip.pypa.io/en/latest/installing/#install-pip )

> curl -kL https://bootstrap.pypa.io/get-pip.py | /opt/local/bin/python2.7
> curl -kL https://bootstrap.pypa.io/get-pip.py | /opt/local/bin/python3.6

VirtualEnv をインストールさせる

/opt/local/bin/pip2.7 install virtualenv
/opt/local/bin/pip3.6 install virtualenv 

thanks sahiruhaさん :thumbsup:

参考

更新ログ

2018/10/04: PIP が推奨する Python のバージョン番号が、 >= 2.7.9, >= 3.4 であったので、3.3 と記述されている部分を 3.6 に変更。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
205