Python3.6インストール yum
今回は、Python学習の事前準備として
yumを使用して、Python 3.6.1 のインストール方法 をご紹介したいと思います。
構築環境
# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
構築手順
では、さっそく始めていきたいと思います。
ユーザの確認
ユーザは、yumを実行するためroot を使用します。
# whoami root
デフォルトのPythonパスの確認
CentOS 7 には、デフォルトで、Python 2.7 がインストールされているため
まずはその確認から行いましょう。
デフォルトのPythonがインストールされているパスを確認しています。
# which python /usr/bin/python
バージョンの確認
次に、バージョンを確認してみます。
デフォルトで、Python 2.7.5 がインストール済であることが確認できました。
# python --version Python 2.7.5
IUSレポジトリ
次に、Python 3.6.1 をyumでインストールしていきたいのですが
Python 3系は、標準のレポジトリでは提供されていないため
単純にyumをしてもインストールできません。
以下のような感じで、存在しませんよとエラーになってしまいます。
# yum install python3.6 Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp No package python3.6 available. Error: Nothing to do
そこで、使用するのがIUSのリポジトリとなります。
Project Goals¶
- Create high quality RPM packages for Red Hat Enterprise Linux (RHEL) and CentOS.
- Promptly release updated RPM packages once new versions are released by the upstream developers.
- No automatic replacement of stock RPM packages.
つまりは、ほぼ最新のバージョンで高品質なRPMパッケージを提供してくれるということです。
では、以下手順で最新のIUSリポジトリを導入します。
IUSレポジトリの確認
まずは、IUSレポジトリが入っていないことを確認しておきます。
※ちなみに、EPELのレポジトリも一緒に確認しています。
YUMでIUSをインストールすると、依存パッケージとして一緒にインストールされるみたいです。
# yum repolist all|egrep 'ius|epel'
IUSレポジトリのインストール
以下コマンドを使用すると最新のIUSレポジトリがインストールされます。
# yum install https://centos7.iuscommunity.org/ius-release.rpm
Python 3.6の検索
では、Python 3.6を検索してみましょう。
# yum search python36 Loaded plugins: fastestmirror, langpacks ius | 2.3 kB 00:00 ius/x86_64/primary_db | 205 kB 00:00 Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.riken.jp * extras: ftp.iij.ad.jp * ius: mirrors.kernel.org * updates: ftp.iij.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 uwsgi-plugin-python36u-debuginfo.x86_64 : Debug information for package : uwsgi-plugin-python36u python36u.x86_64 : Version 3 of the Python programming language aka Python 3000 python36u-debug.x86_64 : Debug version of the Python 3 runtime python36u-devel.x86_64 : Libraries and header files needed for Python 3 : development python36u-gunicorn.noarch : Python WSGI application server python36u-libs.x86_64 : Python 3 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-test.x86_64 : The test modules from the main python 3 package python36u-tkinter.x86_64 : A GUI toolkit for Python 3 python36u-tools.x86_64 : A collection of tools included with Python 3 uwsgi-plugin-python36u.x86_64 : uWSGI - Plugin for Python support Name and summary matches only, use "search all" for everything.
Python 3.6のインストール
検索して表示されたものから、今回はとりあえず以下をインストールします。
# yum install python36u.x86_64 python36u-libs.x86_64 python36u-devel.x86_64 python36u-pip.noarch
インストールバージョンの確認
インストールしたバージョンを確認してみましょう。
バージョンが表示されればインストール成功です。
パスも確認しておきます。
# python3.6 --version Python 3.6.1 # which python3.6 /usr/bin/python3.6
Pythonのリンクを張る
続いてリンクを張りましょう。
これで、python3 としてコマンドが実行できるようになります。
また他の記事だと、元々リンクされているpythonコマンドを
アンリンクしてpython3 で張り直している記事を見かけましたが
OSのコマンドの一部が使えなくなる事象が発生しますのでやめておきましょう。
# ln -s /usr/bin/python3.6 /usr/bin/python3 # ls -l /usr/bin/python* lrwxrwxrwx. 1 root root 7 May 13 12:21 /usr/bin/python -> python2 lrwxrwxrwx. 1 root root 9 May 13 12:21 /usr/bin/python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Nov 5 2016 /usr/bin/python2.7 lrwxrwxrwx 1 root root 18 May 16 07:25 /usr/bin/python3 -> /usr/bin/python3.6 -rwxr-xr-x. 2 root root 11312 Apr 7 07:35 /usr/bin/python3.6 lrwxrwxrwx. 1 root root 26 May 15 09:01 /usr/bin/python3.6-config -> /usr/bin/python3.6m-config -rwxr-xr-x. 2 root root 11312 Apr 7 07:35 /usr/bin/python3.6m -rwxr-xr-x. 1 root root 173 Apr 7 07:34 /usr/bin/python3.6m-config -rwxr-xr-x. 1 root root 3415 Apr 7 07:32 /usr/bin/python3.6m-x86_64-config # python3 --version Python 3.6.1
pipのリンクを張る
pipについては元々張られているリンクなどはなかったため
リンクを張っておきましょう
# which pip3.6 /usr/bin/pip3.6 # ls -l /usr/bin/pip* -rwxr-xr-x. 1 root root 370 Jan 19 10:13 /usr/bin/pip3.6 # ln -s /usr/bin/pip3.6 /usr/bin/pip # ls -l /usr/bin/pip* lrwxrwxrwx 1 root root 15 May 16 07:39 /usr/bin/pip -> /usr/bin/pip3.6 -rwxr-xr-x. 1 root root 370 Jan 19 10:13 /usr/bin/pip3.6 # pip --version pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
以上で完了となりますが、最後に残作業を1点だけ。
インストールしたYUMレポジトリがデフォルトで有効化されているので
通常時はOFFにしておいて、使用する際に、適時ONにするようにします。
それでは、やっていきます。
変更前のファイルコピー
まず変更前のファイルをコピーしておきます。
# cp -p /etc/yum.repos.d/ius.repo /etc/yum.repos.d/ius.repo_`date +%Y%m%d` # cp -p /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo_`date +%Y%m%d`
repoファイル編集
それぞれ、「enabled=1」となっている部分を「enabled=0」へ変更します。
# vi /etc/yum.repos.d/ius.repo # vi /etc/yum.repos.d/epel.repo
ファイルの差分を比較
変更前後のファイルの差分を比較して
以下の出力のように、「enabled=0」と変更されたことを確認してください。
※2番目ファイル後部の「yyyymmdd」は日付が入ります。
# sdiff -s /etc/yum.repos.d/ius.repo /etc/yum.repos.d/ius.repo_yyyymmdd enabled=0 | enabled=1 # sdiff -s /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo_yyyymmdd enabled=0 | enabled=1
disabledの確認
ラスト以下コマンドで IUSとEPEL が
OFFになっていることが確認できれば完了です。
以上で完了となります。
# yum repolist all|egrep 'ius/x86_64|epel/x86_64'|awk '{print $1,$7}' epel/x86_64 disabled ius/x86_64 disabled
皆さんお疲れさまでした。
いかがでしょうか。しっかりとインストールできましたか。
Pythonでプログラムを学ぶ前の準備段階で今回はYUMでインストールしました。
コメント
とても参考になりました!
実は他のサイトでリンクの貼り直しすることが書かれていて、まさにソコにハマってしまっていたところ、こちらにたどり着きました!
ありがとうございました。