Python環境構築手順 CentOS7 Python3.6.5 Python2.7.5

#Python環境構築手順

Pythonの基礎はAidemyで勉強させてもらってるけど、
そろそろ動かしたい。
って事で今回はその環境を構築します。

やっぱり座学だけだと飽きるので、ざーっと基本的なとこ見たら、
環境にも入れ込んでいじり倒したい。

というわけで、まずはPythonの導入。

##環境
* さくらVPS
* CentOS 7
* Python3.6.5
* Python 2.7.5

##参考URL
https://www.python.jp/install/centos/index.html

#構築作業
CentOS 7 では、Python 2.7 がインストールされてる、との事。
パッケージ確認してみる。

```py
[root@ts_server ~]# rpm -qa | grep python
python-perf-3.10.0-327.36.3.el7.x86_64
abrt-addon-python-2.1.11-36.el7.centos.x86_64
libxml2-python-2.9.1-6.el7_2.3.x86_64
python-dmidecode-3.10.13-11.el7.x86_64
python-kitchen-1.1.1-5.el7.noarch
python-iniparse-0.4-9.el7.noarch
newt-python-0.52.15-4.el7.x86_64
python-slip-0.4.0-2.el7.noarch
libreport-python-2.1.11-32.el7.centos.x86_64
python-pycurl-7.19.0-17.el7.x86_64
rpm-python-4.11.3-17.el7.x86_64
abrt-python-2.1.11-36.el7.centos.x86_64
libstoragemgmt-python-1.2.3-4.el7.noarch
dbus-python-1.1.1-9.el7.x86_64
python-chardet-2.2.1-1.el7_1.noarch
python-six-1.9.0-2.el7.noarch
libselinux-python-2.2.2-6.el7.x86_64
python-slip-dbus-0.4.0-2.el7.noarch
python-2.7.5-39.el7_2.x86_64   #←Pythonの本体モジュール。
python-libs-2.7.5-39.el7_2.x86_64
python-urlgrabber-3.10-7.el7.noarch
systemd-python-219-19.el7_2.13.x86_64
python-decorator-3.4.0-3.el7.noarch
python-augeas-0.5.0-2.el7.noarch
python-pyudev-0.15-7.el7_2.1.noarch
python-configobj-4.7.2-7.el7.noarch
langtable-python-0.0.31-3.el7.noarch
[root@ts_server ~]#
```
確かに既に導入されてた。
PythonJapanではPython3.xのインストールを推奨してたので、3.6.5を入れてみる。

IUSを使用してインストールしてみる。
##IUS のリポジトリを yum に追加

```py
[root@ts_server ~]# yum -y install https://centos7.iuscommunity.org/ius-release.rpm
Loaded plugins: fastestmirror, langpacks
ius-release.rpm                                          | 8.1 kB     00:00
Examining /var/tmp/yum-root-MRlzFF/ius-release.rpm: ius-release-1.0-15.ius.centos7.noarch
Marking /var/tmp/yum-root-MRlzFF/ius-release.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package ius-release.noarch 0:1.0-15.ius.centos7 will be installed
--> Finished Dependency Resolution
base/7/x86_64                                            | 3.6 kB     00:00
base/7/x86_64/group_gz                                   | 166 kB     00:00
base/7/x86_64/primary_db                                 | 5.9 MB     00:00
epel/x86_64/metalink                                     | 8.8 kB     00:00
epel/x86_64                                              | 3.2 kB     00:00
epel/x86_64/group_gz                                     |  88 kB     00:00
epel/x86_64/updateinfo                                   | 944 kB     00:00
epel/x86_64/primary                                      | 3.6 MB     00:00
extras/7/x86_64                                          | 3.4 kB     00:00
extras/7/x86_64/primary_db                               | 187 kB     00:00
updates/7/x86_64                                         | 3.4 kB     00:00
updates/7/x86_64/primary_db                              | 5.2 MB     00:00

Dependencies Resolved

================================================================================
 Package          Arch        Version                   Repository         Size
================================================================================
Installing:
 ius-release      noarch      1.0-15.ius.centos7        /ius-release      8.5 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 8.5 k
Installed size: 8.5 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ius-release-1.0-15.ius.centos7.noarch                        1/1
  Verifying  : ius-release-1.0-15.ius.centos7.noarch                        1/1

Installed:
  ius-release.noarch 0:1.0-15.ius.centos7

Complete!
[root@ts_server ~]#
```

##Python 3.6.5のインストール
ついでに拡張モジュールのインストールに必要な開発環境と、pip コマンドも入れる。

```py
[root@ts_server ~]# yum -y install python36u  python36u-devel python36u-pip
Loaded plugins: fastestmirror, langpacks
ius                                                      | 2.3 kB     00:00
ius/x86_64/primary_db                                      | 392 kB   00:02
Determining fastest mirrors
 * base: ftp.iij.ad.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * ius: hkg.mirror.rackspace.com
 * updates: ftp.iij.ad.jp
epel                                                                12686/12686
Resolving Dependencies
--> Running transaction check
---> Package python36u.x86_64 0:3.6.5-1.ius.centos7 will be installed
--> Processing Dependency: python36u-libs(x86-64) = 3.6.5-1.ius.centos7 for package: python36u-3.6.5-1.ius.centos7.x86_64
--> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python36u-3.6.5-1.ius.centos7.x86_64
---> Package python36u-devel.x86_64 0:3.6.5-1.ius.centos7 will be installed
---> Package python36u-pip.noarch 0:9.0.1-1.ius.centos7 will be installed
--> Processing Dependency: python36u-setuptools for package: python36u-pip-9.0.1-1.ius.centos7.noarch
--> Running transaction check
---> Package python36u-libs.x86_64 0:3.6.5-1.ius.centos7 will be installed
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: python36u-libs-3.6.5-1.ius.centos7.x86_64
---> Package python36u-setuptools.noarch 0:39.0.1-1.ius.centos7 will be installed
--> Running transaction check
---> Package openssl-libs.x86_64 1:1.0.1e-51.el7_2.7 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-51.el7_2.7 for package: 1:openssl-1.0.1e-51.el7_2.7.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-51.el7_2.7 will be updated
---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch       Version                     Repository
                                                                           Size
================================================================================
Installing:
 python36u                x86_64     3.6.5-1.ius.centos7         ius       57 k
 python36u-devel          x86_64     3.6.5-1.ius.centos7         ius      839 k
 python36u-pip            noarch     9.0.1-1.ius.centos7         ius      1.8 M
Installing for dependencies:
 python36u-libs           x86_64     3.6.5-1.ius.centos7         ius      8.7 M
 python36u-setuptools     noarch     39.0.1-1.ius.centos7        ius      642 k
Updating for dependencies:
 openssl                  x86_64     1:1.0.2k-12.el7             base     492 k
 openssl-libs             x86_64     1:1.0.2k-12.el7             base     1.2 M

Transaction Summary
================================================================================
Install  3 Packages (+2 Dependent packages)
Upgrade             ( 2 Dependent packages)

Total download size: 14 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/7): openssl-1.0.2k-12.el7.x86_64.rpm                    | 492 kB   00:00
(2/7): openssl-libs-1.0.2k-12.el7.x86_64.rpm               | 1.2 MB   00:00
warning: /var/cache/yum/x86_64/7/ius/packages/python36u-3.6.5-1.ius.centos7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEY
Public key for python36u-3.6.5-1.ius.centos7.x86_64.rpm is not installed
(3/7): python36u-3.6.5-1.ius.centos7.x86_64.rpm            |  57 kB   00:00
(4/7): python36u-devel-3.6.5-1.ius.centos7.x86_64.rpm      | 839 kB   00:02
(5/7): python36u-setuptools-39.0.1-1.ius.centos7.noarch.rp | 642 kB   00:01
(6/7): python36u-pip-9.0.1-1.ius.centos7.noarch.rpm        | 1.8 MB   00:02
(7/7): python36u-libs-3.6.5-1.ius.centos7.x86_64.rpm       | 8.7 MB   00:02
--------------------------------------------------------------------------------
Total                                              4.7 MB/s |  14 MB  00:02
Retrieving key from 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 (@/ius-release)
 From       : /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:openssl-libs-1.0.2k-12.el7.x86_64                          1/9
  Installing : python36u-libs-3.6.5-1.ius.centos7.x86_64                    2/9
  Installing : python36u-3.6.5-1.ius.centos7.x86_64                         3/9
  Installing : python36u-setuptools-39.0.1-1.ius.centos7.noarch             4/9
  Installing : python36u-pip-9.0.1-1.ius.centos7.noarch                     5/9
  Installing : python36u-devel-3.6.5-1.ius.centos7.x86_64                   6/9
  Updating   : 1:openssl-1.0.2k-12.el7.x86_64                               7/9
  Cleanup    : 1:openssl-1.0.1e-51.el7_2.7.x86_64                           8/9
  Cleanup    : 1:openssl-libs-1.0.1e-51.el7_2.7.x86_64                      9/9
  Verifying  : python36u-3.6.5-1.ius.centos7.x86_64                         1/9
  Verifying  : python36u-libs-3.6.5-1.ius.centos7.x86_64                    2/9
  Verifying  : python36u-setuptools-39.0.1-1.ius.centos7.noarch             3/9
  Verifying  : python36u-devel-3.6.5-1.ius.centos7.x86_64                   4/9
  Verifying  : python36u-pip-9.0.1-1.ius.centos7.noarch                     5/9
  Verifying  : 1:openssl-1.0.2k-12.el7.x86_64                               6/9
  Verifying  : 1:openssl-libs-1.0.2k-12.el7.x86_64                          7/9
  Verifying  : 1:openssl-libs-1.0.1e-51.el7_2.7.x86_64                      8/9
  Verifying  : 1:openssl-1.0.1e-51.el7_2.7.x86_64                           9/9

Installed:
  python36u.x86_64 0:3.6.5-1.ius.centos7
  python36u-devel.x86_64 0:3.6.5-1.ius.centos7
  python36u-pip.noarch 0:9.0.1-1.ius.centos7

Dependency Installed:
  python36u-libs.x86_64 0:3.6.5-1.ius.centos7
  python36u-setuptools.noarch 0:39.0.1-1.ius.centos7

Dependency Updated:
  openssl.x86_64 1:1.0.2k-12.el7       openssl-libs.x86_64 1:1.0.2k-12.el7

Complete!
[root@ts_server ~]#
```
無事にインストール完了。

##Python 2.7 のインストール
Python 2.7 はデフォルトでインストール済みだけど、
拡張モジュールのインストールに必要な開発環境と、pip コマンドをインストールをする。

```py
[root@ts_server ~]# yum -y install yum install python2-devel python2-pip
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * ius: hkg.mirror.rackspace.com
 * updates: ftp.iij.ad.jp
No package install available.
Resolving Dependencies
--> Running transaction check
---> Package python-devel.x86_64 0:2.7.5-69.el7_5 will be installed
--> Processing Dependency: python(x86-64) = 2.7.5-69.el7_5 for package: python-devel-2.7.5-69.el7_5.x86_64
---> Package python2-pip.noarch 0:8.1.2-6.el7 will be installed
--> Processing Dependency: python-setuptools for package: python2-pip-8.1.2-6.el7.noarch
---> Package yum.noarch 0:3.4.3-132.el7.centos.0.1 will be updated
---> Package yum.noarch 0:3.4.3-158.el7.centos will be an update
--> Processing Dependency: rpm >= 4.11.3-22 for package: yum-3.4.3-158.el7.centos.noarch
--> Processing Dependency: python-urlgrabber >= 3.10-8 for package: yum-3.4.3-158.el7.centos.noarch
--> Running transaction check
---> Package python.x86_64 0:2.7.5-39.el7_2 will be updated
---> Package python.x86_64 0:2.7.5-69.el7_5 will be an update
--> Processing Dependency: python-libs(x86-64) = 2.7.5-69.el7_5 for package: python-2.7.5-69.el7_5.x86_64
---> Package python-setuptools.noarch 0:0.9.8-7.el7 will be installed
--> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-7.el7.noarch
---> Package python-urlgrabber.noarch 0:3.10-7.el7 will be updated
---> Package python-urlgrabber.noarch 0:3.10-8.el7 will be an update
---> Package rpm.x86_64 0:4.11.3-17.el7 will be updated
--> Processing Dependency: rpm = 4.11.3-17.el7 for package: rpm-libs-4.11.3-17.el7.x86_64
--> Processing Dependency: rpm = 4.11.3-17.el7 for package: rpm-python-4.11.3-17.el7.x86_64
--> Processing Dependency: rpm = 4.11.3-17.el7 for package: rpm-build-4.11.3-17.el7.x86_64
---> Package rpm.x86_64 0:4.11.3-32.el7 will be an update
--> Running transaction check
---> Package python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 will be installed
--> Processing Dependency: python-ipaddress for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
--> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
---> Package python-libs.x86_64 0:2.7.5-39.el7_2 will be updated
---> Package python-libs.x86_64 0:2.7.5-69.el7_5 will be an update
---> Package rpm-build.x86_64 0:4.11.3-17.el7 will be updated
---> Package rpm-build.x86_64 0:4.11.3-32.el7 will be an update
---> Package rpm-libs.x86_64 0:4.11.3-17.el7 will be updated
--> Processing Dependency: rpm-libs(x86-64) = 4.11.3-17.el7 for package: rpm-build-libs-4.11.3-17.el7.x86_64
---> Package rpm-libs.x86_64 0:4.11.3-32.el7 will be an update
---> Package rpm-python.x86_64 0:4.11.3-17.el7 will be updated
---> Package rpm-python.x86_64 0:4.11.3-32.el7 will be an update
--> Running transaction check
---> Package python-backports.x86_64 0:1.0-8.el7 will be installed
---> Package python-ipaddress.noarch 0:1.0.16-2.el7 will be installed
---> Package rpm-build-libs.x86_64 0:4.11.3-17.el7 will be updated
--> Processing Dependency: rpm-build-libs(x86-64) = 4.11.3-17.el7 for package: rpm-sign-4.11.3-17.el7.x86_64
---> Package rpm-build-libs.x86_64 0:4.11.3-32.el7 will be an update
--> Running transaction check
---> Package rpm-sign.x86_64 0:4.11.3-17.el7 will be updated
---> Package rpm-sign.x86_64 0:4.11.3-32.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                             Arch   Version               Repository
                                                                           Size
================================================================================
Installing:
 python-devel                        x86_64 2.7.5-69.el7_5        updates 397 k
 python2-pip                         noarch 8.1.2-6.el7           epel    1.7 M
Updating:
 yum                                 noarch 3.4.3-158.el7.centos  base    1.2 M
Installing for dependencies:
 python-backports                    x86_64 1.0-8.el7             base    5.8 k
 python-backports-ssl_match_hostname noarch 3.5.0.1-1.el7         base     13 k
 python-ipaddress                    noarch 1.0.16-2.el7          base     34 k
 python-setuptools                   noarch 0.9.8-7.el7           base    397 k
Updating for dependencies:
 python                              x86_64 2.7.5-69.el7_5        updates  93 k
 python-libs                         x86_64 2.7.5-69.el7_5        updates 5.6 M
 python-urlgrabber                   noarch 3.10-8.el7            base    108 k
 rpm                                 x86_64 4.11.3-32.el7         base    1.2 M
 rpm-build                           x86_64 4.11.3-32.el7         base    147 k
 rpm-build-libs                      x86_64 4.11.3-32.el7         base    105 k
 rpm-libs                            x86_64 4.11.3-32.el7         base    276 k
 rpm-python                          x86_64 4.11.3-32.el7         base     82 k
 rpm-sign                            x86_64 4.11.3-32.el7         base     47 k

Transaction Summary
================================================================================
Install  2 Packages (+4 Dependent packages)
Upgrade  1 Package  (+9 Dependent packages)

Total download size: 11 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/16): python-backports-1.0-8.el7.x86_64.rpm              | 5.8 kB   00:00
(2/16): python-2.7.5-69.el7_5.x86_64.rpm                   |  93 kB   00:00
(3/16): python-backports-ssl_match_hostname-3.5.0.1-1.el7. |  13 kB   00:00
(4/16): python-ipaddress-1.0.16-2.el7.noarch.rpm           |  34 kB   00:00
(5/16): python-devel-2.7.5-69.el7_5.x86_64.rpm             | 397 kB   00:00
(6/16): python-setuptools-0.9.8-7.el7.noarch.rpm           | 397 kB   00:00
(7/16): python-urlgrabber-3.10-8.el7.noarch.rpm            | 108 kB   00:00
(8/16): rpm-build-libs-4.11.3-32.el7.x86_64.rpm            | 105 kB   00:00
(9/16): rpm-build-4.11.3-32.el7.x86_64.rpm                 | 147 kB   00:00
(10/16): python2-pip-8.1.2-6.el7.noarch.rpm                | 1.7 MB   00:00
(11/16): rpm-libs-4.11.3-32.el7.x86_64.rpm                 | 276 kB   00:00
(12/16): rpm-python-4.11.3-32.el7.x86_64.rpm               |  82 kB   00:00
(13/16): rpm-sign-4.11.3-32.el7.x86_64.rpm                 |  47 kB   00:00
(14/16): yum-3.4.3-158.el7.centos.noarch.rpm               | 1.2 MB   00:00
(15/16): python-libs-2.7.5-69.el7_5.x86_64.rpm             | 5.6 MB   00:01
(16/16): rpm-4.11.3-32.el7.x86_64.rpm                      | 1.2 MB   00:00
--------------------------------------------------------------------------------
Total                                              6.2 MB/s |  11 MB  00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : rpm-4.11.3-32.el7.x86_64                                    1/26
  Updating   : rpm-libs-4.11.3-32.el7.x86_64                               2/26
  Updating   : rpm-build-libs-4.11.3-32.el7.x86_64                         3/26
  Updating   : python-libs-2.7.5-69.el7_5.x86_64                           4/26
  Updating   : python-2.7.5-69.el7_5.x86_64                                5/26
  Updating   : python-urlgrabber-3.10-8.el7.noarch                         6/26
  Installing : python-backports-1.0-8.el7.x86_64                           7/26
  Updating   : rpm-python-4.11.3-32.el7.x86_64                             8/26
  Installing : python-ipaddress-1.0.16-2.el7.noarch                        9/26
  Installing : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch   10/26
  Installing : python-setuptools-0.9.8-7.el7.noarch                       11/26
  Installing : python2-pip-8.1.2-6.el7.noarch                             12/26
  Updating   : yum-3.4.3-158.el7.centos.noarch                            13/26
  Installing : python-devel-2.7.5-69.el7_5.x86_64                         14/26
  Updating   : rpm-sign-4.11.3-32.el7.x86_64                              15/26
  Updating   : rpm-build-4.11.3-32.el7.x86_64                             16/26
  Cleanup    : yum-3.4.3-132.el7.centos.0.1.noarch                        17/26
  Cleanup    : rpm-python-4.11.3-17.el7.x86_64                            18/26
  Cleanup    : rpm-build-4.11.3-17.el7.x86_64                             19/26
  Cleanup    : rpm-sign-4.11.3-17.el7.x86_64                              20/26
  Cleanup    : python-urlgrabber-3.10-7.el7.noarch                        21/26
  Cleanup    : python-2.7.5-39.el7_2.x86_64                               22/26
  Cleanup    : rpm-build-libs-4.11.3-17.el7.x86_64                        23/26
  Cleanup    : rpm-4.11.3-17.el7.x86_64                                   24/26
  Cleanup    : rpm-libs-4.11.3-17.el7.x86_64                              25/26
  Cleanup    : python-libs-2.7.5-39.el7_2.x86_64                          26/26
  Verifying  : rpm-sign-4.11.3-32.el7.x86_64                               1/26
  Verifying  : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch    2/26
  Verifying  : rpm-build-libs-4.11.3-32.el7.x86_64                         3/26
  Verifying  : python-setuptools-0.9.8-7.el7.noarch                        4/26
  Verifying  : python-urlgrabber-3.10-8.el7.noarch                         5/26
  Verifying  : python2-pip-8.1.2-6.el7.noarch                              6/26
  Verifying  : yum-3.4.3-158.el7.centos.noarch                             7/26
  Verifying  : python-libs-2.7.5-69.el7_5.x86_64                           8/26
  Verifying  : rpm-build-4.11.3-32.el7.x86_64                              9/26
  Verifying  : python-backports-1.0-8.el7.x86_64                          10/26
  Verifying  : python-2.7.5-69.el7_5.x86_64                               11/26
  Verifying  : python-devel-2.7.5-69.el7_5.x86_64                         12/26
  Verifying  : rpm-python-4.11.3-32.el7.x86_64                            13/26
  Verifying  : python-ipaddress-1.0.16-2.el7.noarch                       14/26
  Verifying  : rpm-libs-4.11.3-32.el7.x86_64                              15/26
  Verifying  : rpm-4.11.3-32.el7.x86_64                                   16/26
  Verifying  : rpm-sign-4.11.3-17.el7.x86_64                              17/26
  Verifying  : rpm-build-libs-4.11.3-17.el7.x86_64                        18/26
  Verifying  : python-2.7.5-39.el7_2.x86_64                               19/26
  Verifying  : rpm-build-4.11.3-17.el7.x86_64                             20/26
  Verifying  : rpm-4.11.3-17.el7.x86_64                                   21/26
  Verifying  : rpm-libs-4.11.3-17.el7.x86_64                              22/26
  Verifying  : python-libs-2.7.5-39.el7_2.x86_64                          23/26
  Verifying  : yum-3.4.3-132.el7.centos.0.1.noarch                        24/26
  Verifying  : rpm-python-4.11.3-17.el7.x86_64                            25/26
  Verifying  : python-urlgrabber-3.10-7.el7.noarch                        26/26

Installed:
  python-devel.x86_64 0:2.7.5-69.el7_5     python2-pip.noarch 0:8.1.2-6.el7

Dependency Installed:
  python-backports.x86_64 0:1.0-8.el7
  python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7
  python-ipaddress.noarch 0:1.0.16-2.el7
  python-setuptools.noarch 0:0.9.8-7.el7

Updated:
  yum.noarch 0:3.4.3-158.el7.centos

Dependency Updated:
  python.x86_64 0:2.7.5-69.el7_5         python-libs.x86_64 0:2.7.5-69.el7_5
  python-urlgrabber.noarch 0:3.10-8.el7  rpm.x86_64 0:4.11.3-32.el7
  rpm-build.x86_64 0:4.11.3-32.el7       rpm-build-libs.x86_64 0:4.11.3-32.el7
  rpm-libs.x86_64 0:4.11.3-32.el7        rpm-python.x86_64 0:4.11.3-32.el7
  rpm-sign.x86_64 0:4.11.3-32.el7

Complete!
[root@ts_server ~]#
```
無事にインストール完了。

##Pythonの実行確認
Python各バージョンは次のコマンドで実行

* Python3.6の起動

```py

[root@ts_server ~]# python3.6
Python 3.6.5 (default, Apr 10 2018, 17:08:37)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help
Type help() for interactive help, or help(object) for help about object.
>>>
[root@ts_server ~]#
```

* Python2.7.5の起動

```py
[root@ts_server ~]# python
Python 2.7.5 (default, Jul 13 2018, 13:06:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help
Type help() for interactive help, or help(object) for help about object.
>>>
[root@ts_server ~]#
```

どちらも起動確認までは完了。

#仮想環境
Python2とPython3と切り分けて使いたいので、仮想環境を入れておく。
Virtualenvを導入する。

```py
[root@ts_server ~]# python3.6 -m pip install virtualenv
Collecting virtualenv
  Downloading https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
    100% |################################| 1.9MB 459kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-16.0.0
You are using pip version 9.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@ts_server ~]#
```

適当な作業フォルダを作成する。

```py

[root@ts_server ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda4      100138988 1778952  98360036   2% /
devtmpfs          499032       0    499032   0% /dev
tmpfs             508380       0    508380   0% /dev/shm
tmpfs             508380   13060    495320   3% /run
tmpfs             508380       0    508380   0% /sys/fs/cgroup
/dev/vda2         508588  135904    372684  27% /boot
tmpfs             101676       0    101676   0% /run/user/0
tmpfs             101676       0    101676   0% /run/user/1000
[root@ts_server ~]#
[root@ts_server ~]# cd /opt
[root@ts_server opt]# pwd
/opt
[root@ts_server opt]# ls -ltr
total 0
drwxr-xr-x. 2 root root 6 Mar 26  2015 rh
[root@ts_server opt]# mkdir python_run
[root@ts_server opt]# chmod 777 python_run
[root@ts_server opt]# cd python_run
[root@ts_server python_run]# pwd
/opt/python_run
[root@ts_server python_run]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda4      100138988 1810936  98328052   2% /
devtmpfs          499032       0    499032   0% /dev
tmpfs             508380       0    508380   0% /dev/shm
tmpfs             508380   13060    495320   3% /run
tmpfs             508380       0    508380   0% /sys/fs/cgroup
/dev/vda2         508588  135904    372684  27% /boot
tmpfs             101676       0    101676   0% /run/user/0
tmpfs             101676       0    101676   0% /run/user/1000
[root@ts_server python_run]# 
```
仮想環境作成コマンド実行

```py
[root@ts_server python_run]# virtualenv py3env
Using base prefix '/usr'
New python executable in /opt/python_run/py3env/bin/python3.6
Also creating executable in /opt/python_run/py3env/bin/python
Installing setuptools, pip, wheel...done.
[root@ts_server python_run]# 

```

仮想環境アクティベート

```py

[root@ts_server python_run]# . ./py3env/bin/activate
(py3env) [root@ts_server python_run]#

```

アクティベートした状態でPython起動すると、仮想環境のバージョン(今回だとPython3.6.5)が起動する。

```py
(py3env) [root@ts_server python_run]# python
Python 3.6.5 (default, Apr 10 2018, 17:08:37)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
```

この仮想環境にはパッケージのインストールなども出来るけど、元のPythonには手は加わらない。
プロジェクトごとに分けたい場合に有効だと思う。
戻る時はdeactivateする。

```py
>>>
(py3env) [root@ts_server python_run]# deactivate
[root@ts_server python_run]#
```

Python2.7にも仮想環境を入れておく。

```py

[root@ts_server python_run]# python2.7 -m pip install virtualenv
Collecting virtualenv
  Using cached https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-16.0.0
You are using pip version 8.1.2, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@ts_server python_run]#
```

Python2.7の仮想環境も作ってみる。

```py
[root@ts_server python_run]# python2.7 -m virtualenv py27env
New python executable in /opt/python_run/py27env/bin/python2.7
Also creating executable in /opt/python_run/py27env/bin/python
Installing setuptools, pip, wheel...done.
[root@ts_server python_run]#
[root@ts_server python_run]# ls -l
total 0
drwxr-xr-x 5 root root 77 Sep 23 00:46 py27env
drwxr-xr-x 5 root root 77 Sep 23 00:27 py3env
[root@ts_server python_run]#
```

アクティベートして、Pythonを起動できる事を確認する。

```py

[root@ts_server python_run]# . py27env/bin/activate
(py27env) [root@ts_server python_run]# python
Python 2.7.5 (default, Jul 13 2018, 13:06:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
(py27env) [root@ts_server python_run]# deactivate
[root@ts_server python_run]#

```

環境構築はここまで。
PythonJapanの通りにコマンド叩いたら特に引っかかるとこなしでした。