VMWare上のCentOS6にpython3系をインストール

習慣化162日目

python3系をインストールする

インストールされているpythonを確認する

[root@centos6 /]# python
python     python2    python2.6
[root@centos6 /]# python --version
Python 2.6.6
[root@centos6 /]#

リポジトリを追加してインストール

リポジトリの追加

[root@centos6 /]# yum install -y https://repo.ius.io/ius-release-el6.rpm

次のバージョンがあったりしないのか確認しておく これで確認できるのかよく分からないが

[root@centos6 /]# yum search python37
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: nrt.edge.kernel.org
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
警告: 一致するものが見つかりません: python37
見つかりませんでした
[root@centos6 /]#

python3系をインストール

[root@centos6 /]# yum install -y python36*

エイリアスを設定

[root@centos6 /]# ls /usr/bin/python3
ls: cannot access /usr/bin/python3: そのようなファイルやディレクトリはありません
[root@centos6 /]# ln -s /usr/bin/python3.6 /usr/bin/python3
[root@centos6 /]# ln -s /usr/bin/pip3.6 /usr/bin/pip3

[root@centos6 /]# python
python                     python3.6                  python3.6dm-config         python3.6m-x86_64-config
python2                    python3.6-config           python3.6dm-x86_64-config  python36
python2.6                  python3.6-debug            python3.6m
python3                    python3.6dm                python3.6m-config
[root@centos6 /]# python3 --version
Python 3.6.8

動かしてみる

[root@centos6 ~]# vi check.py

[root@centos6 ~]# cat check.py
#!/usr/bin/python3

print('this is a pen')

[root@centos6 ~]# chmod +x check.py
[root@centos6 ~]# ./check.py
this is a pen
[root@centos6 ~]#