[Python] CentOS7へのインストール

PythonをCentOS7にインストールする方法です。yumで簡単にインストールできます。
インストールしてターミナルからすぐにPhthonを実行することができました。

IUSリポジトリ設定

インストール前に「IUS」リポジトリをyumで追加します。

# yum install -y https://centos7.iuscommunity.org/ius-release.rpm

上記コマンドを入力すると、下記のような画面になります。

読み込んだプラグイン:fastestmirror, langpacks
ius-release.rpm                                          | 8.1 kB     00:00
/var/tmp/yum-root-Egq1NY/ius-release.rpm を調べています: ius-release-1.0-15.ius.                                      centos7.noarch
/var/tmp/yum-root-Egq1NY/ius-release.rpm をインストール済みとして設定しています
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ ius-release.noarch 0:1.0-15.ius.centos7 を インストール
--> 依存性の処理をしています: epel-release = 7 のパッケージ: ius-release-1.0-15.                                      ius.centos7.noarch
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
mysql-connectors-community                               | 2.5 kB     00:00
mysql-tools-community                                    | 2.5 kB     00:00
mysql57-community                                        | 2.5 kB     00:00
updates                                                  | 3.4 kB     00:00
updates/7/x86_64/primary_db                                | 6.9 MB   00:00
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
--> トランザクションの確認を実行しています。
---> パッケージ epel-release.noarch 0:7-9 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package           アーキテクチャー
                               バージョン               リポジトリー       容量
================================================================================
インストール中:
 ius-release       noarch      1.0-15.ius.centos7       /ius-release      8.5 k
依存性関連でのインストールをします:
 epel-release      noarch      7-9                      extras             14 k

トランザクションの要約
================================================================================
インストール  1 パッケージ (+1 個の依存関係のパッケージ)

合計容量: 23 k
総ダウンロード容量: 14 k
インストール容量: 33 k
Downloading packages:
epel-release-7-9.noarch.rpm                                |  14 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : epel-release-7-9.noarch                         1/2
  インストール中          : ius-release-1.0-15.ius.centos7.noarch           2/2
  検証中                  : ius-release-1.0-15.ius.centos7.noarch           1/2
  検証中                  : epel-release-7-9.noarch                         2/2

インストール:
  ius-release.noarch 0:1.0-15.ius.centos7

依存性関連をインストールしました:
  epel-release.noarch 0:7-9

完了しました!

yumでPythonをインストール

yumで pythonのバージョンを確認

 yum search python36

上記コマンドで下記の画面が表示されます。

読み込んだプラグイン:fastestmirror, langpacks
epel/x86_64/metalink                                                                           | 7.4 kB  00:00:00
epel                                                                                           | 4.7 kB  00:00:00
ius                                                                                            | 2.3 kB  00:00:00
(1/4): epel/x86_64/group_gz                                                                    | 266 kB  00:00:00
(2/4): epel/x86_64/updateinfo                                                                  | 904 kB  00:00:00
(3/4): epel/x86_64/primary_db                                                                  | 6.3 MB  00:00:00
(4/4): ius/x86_64/primary_db                                                                   | 251 kB  00:00:02
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * ius: mirrors.tongji.edu.cn
 * updates: ftp.tsukuba.wide.ad.jp
=============================================== N/S matched: python36 ================================================
python36u-debuginfo.x86_64 : Debug information for package python36u
python36u-lxml-debuginfo.x86_64 : Debug information for package python36u-lxml
python36u-mod_wsgi-debuginfo.x86_64 : Debug information for package python36u-mod_wsgi
python36u-psycopg2-debuginfo.x86_64 : Debug information for package python36u-psycopg2
python36u-setproctitle-debuginfo.x86_64 : Debug information for package python36u-setproctitle
python36u-test.x86_64 : The self-test suite for the main python36u package
uwsgi-plugin-python36u-debuginfo.x86_64 : Debug information for package uwsgi-plugin-python36u
python36.x86_64 : Interpreter of the Python programming language
python36-debug.x86_64 : Debug version of the Python runtime
python36-devel.x86_64 : Libraries and header files needed for Python development
python36-libs.x86_64 : Python runtime libraries
python36-test.x86_64 : The self-test suite for the main python3 package
python36-tkinter.x86_64 : A GUI toolkit for Python
python36-tools.x86_64 : A collection of tools included with Python including 2to3 and idle
python36u.x86_64 : Interpreter of the Python programming language
python36u-debug.x86_64 : Debug version of the Python runtime
python36u-devel.x86_64 : Libraries and header files needed for Python development
python36u-gunicorn.noarch : Python WSGI application server
python36u-libs.x86_64 : Python runtime libraries
python36u-lxml.x86_64 : XML processing library combining libxml2/libxslt with the ElementTree API
python36u-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python36u-pip.noarch : A tool for installing and managing Python packages
python36u-psycopg2.x86_64 : A PostgreSQL database adapter for Python
python36u-redis.noarch : Python interface to the Redis key-value store
python36u-setproctitle.x86_64 : Python module to customize a process title
python36u-setuptools.noarch : Easily build and distribute Python packages
python36u-tkinter.x86_64 : A GUI toolkit for Python
python36u-tools.x86_64 : A collection of tools included with Python including 2to3 and idle
uwsgi-plugin-python36u.x86_64 : uWSGI - Plugin for Python support

  Name and summary matches only, use "search all" for everything.

phthonのインストール

必要なパッケージをインストールします。

yum install python36u python36u-libs python36u-pip python36u-devel

下記の画面が出力されます。途中何度かyes noの選択があるので「y」を入力してENTERを押します。

読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * ius: hkg.mirror.rackspace.com
 * updates: ftp.tsukuba.wide.ad.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ python36u.x86_64 0:3.6.4-1.ius.centos7 を インストール
---> パッケージ python36u-devel.x86_64 0:3.6.4-1.ius.centos7 を インストール
---> パッケージ python36u-libs.x86_64 0:3.6.4-1.ius.centos7 を インストール
---> パッケージ python36u-pip.noarch 0:9.0.1-1.ius.centos7 を インストール
--> 依存性の処理をしています: python36u-setuptools のパッケージ: python36u-pip-9.0.1-1.ius.centos7.noarch
--> トランザクションの確認を実行しています。
---> パッケージ python36u-setuptools.noarch 0:36.6.0-1.ius.centos7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

======================================================================================================================
 Package                            アーキテクチャー     バージョン                           リポジトリー       容量
======================================================================================================================
インストール中:
 python36u                          x86_64               3.6.4-1.ius.centos7                  ius                56 k
 python36u-devel                    x86_64               3.6.4-1.ius.centos7                  ius               839 k
 python36u-libs                     x86_64               3.6.4-1.ius.centos7                  ius               8.7 M
 python36u-pip                      noarch               9.0.1-1.ius.centos7                  ius               1.8 M
依存性関連でのインストールをします:
 python36u-setuptools               noarch               36.6.0-1.ius.centos7                 ius               587 k

トランザクションの要約
======================================================================================================================
インストール  4 パッケージ (+1 個の依存関係のパッケージ)

総ダウンロード容量: 12 M
インストール容量: 53 M
Is this ok [y/d/N]: y
Downloading packages:
警告: /var/cache/yum/x86_64/7/ius/packages/python36u-3.6.4-1.ius.centos7.x86_64.rpm: ヘッダー V4 DSA/SHA1 Signature、 鍵 ID 9cd4953f: NOKEY
python36u-3.6.4-1.ius.centos7.x86_64.rpm の公開鍵がインストールされていません
(1/5): python36u-3.6.4-1.ius.centos7.x86_64.rpm                                                |  56 kB  00:00:00
(2/5): python36u-setuptools-36.6.0-1.ius.centos7.noarch.rpm                                    | 587 kB  00:00:01
(3/5): python36u-devel-3.6.4-1.ius.centos7.x86_64.rpm                                          | 839 kB  00:00:02
(4/5): python36u-pip-9.0.1-1.ius.centos7.noarch.rpm                                            | 1.8 MB  00:00:02
(5/5): python36u-libs-3.6.4-1.ius.centos7.x86_64.rpm                                           | 8.7 MB  00:00:03
----------------------------------------------------------------------------------------------------------------------
合計                                                                                  3.6 MB/s |  12 MB  00:00:03
file:///etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY から鍵を取得中です。
Importing GPG key 0x9CD4953F:
 Userid     : "IUS Community Project <coredev@iuscommunity.org>"
 Fingerprint: 8b84 6e3a b3fe 6462 74e8 670f da22 1cdf 9cd4 953f
 Package    : ius-release-1.0-15.ius.centos7.noarch (installed)
 From       : /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY
上記の処理を行います。よろしいでしょうか? [y/N]y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : python36u-libs-3.6.4-1.ius.centos7.x86_64                                             1/5
  インストール中          : python36u-3.6.4-1.ius.centos7.x86_64                                                  2/5
  インストール中          : python36u-setuptools-36.6.0-1.ius.centos7.noarch                                      3/5
  インストール中          : python36u-pip-9.0.1-1.ius.centos7.noarch                                              4/5
  インストール中          : python36u-devel-3.6.4-1.ius.centos7.x86_64                                            5/5
  検証中                  : python36u-setuptools-36.6.0-1.ius.centos7.noarch                                      1/5
  検証中                  : python36u-pip-9.0.1-1.ius.centos7.noarch                                              2/5
  検証中                  : python36u-3.6.4-1.ius.centos7.x86_64                                                  3/5
  検証中                  : python36u-libs-3.6.4-1.ius.centos7.x86_64                                             4/5
  検証中                  : python36u-devel-3.6.4-1.ius.centos7.x86_64                                            5/5

インストール:
  python36u.x86_64 0:3.6.4-1.ius.centos7                    python36u-devel.x86_64 0:3.6.4-1.ius.centos7
  python36u-libs.x86_64 0:3.6.4-1.ius.centos7               python36u-pip.noarch 0:9.0.1-1.ius.centos7

依存性関連をインストールしました:
  python36u-setuptools.noarch 0:36.6.0-1.ius.centos7

完了しました!

Pythonのバージョン確認

python --version

[出力結果]

Python 2.7.5

あれ?バージョン3.6をインストールしたつもりが、バージョンが2.7.5と出力されてしまいました。これはCentOS7にデフォルトで2.xがインストールしてあるためです。

インストールした3.6を確認するには

python3.6 --version

[出力結果]

Python 3.6.4


Author: webmaster