LoginSignup
39
44

More than 5 years have passed since last update.

CentOS7にpython3系のインストール

Last updated at Posted at 2016-08-04

CentOS7にはデフォルトでpython2系が入っています。
python3を勉強用で使いたいので最新版をインストールしますが、python2系も共存させてどちらも使えるように設定します。

環境
CentOS Linux release 7.2.1511 (Core)

必要な依存関係をインストール

$ yum install gcc zlib-devel bzip2 bzip2-devel readline readline-devel sqlite sqlite-devel openssl openssl-devel git
pyenvインストール

pyenvをインストールすることで複数のバージョンのpythonを共存させて簡単に切り替えることができます。


$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
bash_profileに環境変数を記述します。

$ vim .bash_profile
下記を追記
$ pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
bash_profileを反映。

$ source .bash_profile
python3系のインストール

インストールできるバージョンを一覧表示

$ pyenv install --list
3.5.1をインストール


$ pyenv install 3.5.1
pythonのバージョンを確認


$ python --version
Python 2.7.5
python3.5.1に切り替え


$ pyenv global 3.5.1
$ pyenv rehash
$ python --version
Python 3.5.1
利用可能なバージョンが表示


$ pyenv versions
  system
* 3.5.1 (set by /root/.pyenv/version)
systemに切り替えるとバージョンが2.7.5に戻ります。


$ pyenv global system
$ python --version
Python 2.7.5
39
44
0

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
39
44