2016年2月4日木曜日

Oracle Linux 6.x で Python 3.3 を使用してみる。(SCL)

Oracle Linux 6.x では、標準では Python 2.6.x がインストールされます。
そして、そのバージョンでアップデートされていきます。

しかし Python 3.x を使用したいため、
Oracle Linux らしい方法を模索してみました。

ということで、
Software Collection Library for Oracle Linux(SCL)を使ってみます。

Software Collection Library 1.2 for Oracle Linux
テクノロジ・プレビュー・リリース・ノート

SCL を利用した、Python 3.3 インストール。

今回は、Oracle Linux 6.7 です。
ちなみに、Docker Hub の oraclelinux:6 イメージを使用しています。
[root@c800cb100ffa /]# cat /etc/oracle-release
Oracle Linux Server release 6.7

まず、最新の Yum リポジトリファイルをダウンロードします。
[root@c800cb100ffa /]# curl http://public-yum.oracle.com/public-yum-ol6.repo -o /etc/yum.repos.d/public-yum-ol6.repo

ダウンロードした /etc/yum.repos.d/public-yum-ol6.repo  ファイルには、
末尾にこの設定が含まれています。デフォルトでは無効(enabled=0)です。
[ol6_software_collections]
name=Software Collection Library release 1.2 packages for Oracle Linux 6 (x86_64)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/SoftwareCollections12/x86_64/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=0

OL6 の最新の RPM が含まれる ol6_latest と、
ol6_software_collections リポジトリを有効にして、
Python 3.3 環境の RPM、python33 をインストールします。
easy_install を使用するため、python33-python-setuptools もインストールします。
[root@c800cb100ffa /]# yum --enablerepo=ol6_latest,ol6_software_collections install -y python33 python33-python-setuptools

ちなみに、このような PRM が依存関係によりインストールされます。
SCL の scl-utils もインストールされます。
Installed:
  python33.x86_64 0:1.1-12.el6   python33-python-setuptools.noarch 0:0.9.8-1.el6

Dependency Installed:
  python33-python.x86_64 0:3.3.2-14.el6
  python33-python-devel.x86_64 0:3.3.2-14.el6
  python33-python-docutils.noarch 0:0.11-1.el6
  python33-python-jinja2.noarch 0:2.6-11.el6
  python33-python-libs.x86_64 0:3.3.2-14.el6
  python33-python-markupsafe.noarch 0:0.11-10.el6
  python33-python-nose.noarch 0:1.3.0-1.el6
  python33-python-pygments.noarch 0:1.5-3.el6
  python33-python-simplejson.x86_64 0:3.2.0-1.el6
  python33-python-sphinx.noarch 0:1.1.3-8.el6
  python33-python-sqlalchemy.noarch 0:0.7.9-4.el6
  python33-python-virtualenv.noarch 0:1.10.1-1.el6
  python33-runtime.x86_64 0:1.1-12.el6
  scl-utils.x86_64 0:20120927-27.el6_6

SCL で Python 3.3 を使用してみる。

この RPM をインストールしただけでは、
Python 3.3 ではなく従来の Python 2.6 系が使用されます。
[root@c800cb100ffa /]# python -V
Python 2.6.6

SCL で、python 3.3 がインストールされたことを確認してみます。
ソフトウェアコレクション「python33」が表示されます。
[root@c800cb100ffa /]# scl --list
python33

それでは、Python 3.3 を使用してみます。
scl コマンドで、ソフトウェアコレクションとして「python33」を指定します。
そして、「--」のあとが実行するコマンドラインです。
scl コマンド使用後も、普通に python を実行するともともとのバージョンのままです。
[root@c800cb100ffa /]# scl enable python33 -- python -V
Python 3.3.2
[root@c800cb100ffa /]# python -V
Python 2.6.6

このような感じでスクリプトを実行できます。
Python 2.6、SCL の Python 3.3 それぞれでスクリプトファイルを実行してみます。
[root@c800cb100ffa /]# echo 'import sys; print(sys.version_info)' > test.py
[root@c800cb100ffa /]# python test.py
(2, 6, 6, 'final', 0)
[root@c800cb100ffa /]# scl enable python33 -- python test.py
sys.version_info(major=3, minor=3, micro=2, releaselevel='final', serial=0)

それぞれの python のパスはここです。
[root@c800cb100ffa /]# which python
/usr/bin/python
[root@c800cb100ffa /]# scl enable python33 -- which python
/opt/rh/python33/root/usr/bin/python

easy_install、pip を使用してみる。

SCL python33 には、easy_install が含まれていています。
ためしに、easy_install で pip をインストールしてみます。
[root@c800cb100ffa /]# scl enable python33 -- easy_install pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 8.0.2
Downloading https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
Processing pip-8.0.2.tar.gz
Writing /tmp/easy_install-s2ha5z/pip-8.0.2/setup.cfg
Running pip-8.0.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-s2ha5z/pip-8.0.2/egg-dist-tmp-pxnvjm
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 8.0.2 to easy-install.pth file
Installing pip3 script to /opt/rh/python33/root/usr/bin
Installing pip3.3 script to /opt/rh/python33/root/usr/bin
Installing pip script to /opt/rh/python33/root/usr/bin

Installed /opt/rh/python33/root/usr/lib/python3.3/site-packages/pip-8.0.2-py3.3.egg
Processing dependencies for pip
Finished processing dependencies for pip

pip が使用できるようになりました。
[root@c800cb100ffa /]# scl enable python33 -- pip freeze
docutils==0.11
Jinja2==2.6
MarkupSafe==0.11
nose==1.3.0
Pygments==1.5
simplejson==3.2.0
Sphinx==1.1.3
SQLAlchemy==0.7.9
virtualenv==1.10.1

scl コマンドなしで Python 3.3 を使用してみる。

ソフトウェアコレクションには /opt/rh/python33/enable という
環境変数の定義ファイルが用意されていて、
このファイルを source コマンド(もしくは「.」)で読み込むと、
普通に Python 3.3 が使えるようになります。

/opt/rh/python33/enable ファイルは、python33-runtime に含まれます。
[root@c800cb100ffa /]# rpm -qf /opt/rh/python33/enable
python33-runtime-1.1-12.el6.x86_64

ファイルの内容です。
[root@c800cb100ffa /]# cat /opt/rh/python33/enable
export PATH=/opt/rh/python33/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/python33/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/python33/root/usr/share/man:${MANPATH}
# For systemtap
export XDG_DATA_DIRS=/opt/rh/python33/root/usr/share${XDG_DATA_DIRS:+:${XDG_DATA_DIRS}}
# For pkg-config
export PKG_CONFIG_PATH=/opt/rh/python33/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}

このファイルを読み込むとサーチパスなどが通って、
scl コマンドなしで python を実行しても 3.3 になります。
[root@c800cb100ffa /]# source /opt/rh/python33/enable
[root@c800cb100ffa /]# which python
/opt/rh/python33/root/usr/bin/python
[root@c800cb100ffa /]# python -V
Python 3.3.2

おまけ。

ちなみに SCL には、Python 2.7 のソフトウェアコレクションもあります。
[root@c800cb100ffa /]# yum --enablerepo=ol6_latest,ol6_software_collections list p
ython27

Loaded plugins: security, ulninfo
Available Packages
python27.x86_64                1.1-16.el6                 ol6_software_collections
[root@c800cb100ffa /]# yum --enablerepo=ol6_latest,ol6_software_collections list python27-python
Loaded plugins: security, ulninfo
Available Packages
python27-python.x86_64            2.7.5-10.el6            ol6_software_collections

Yum リポジトリを見ると、ほかにも Ruby や PHP などいろいろあります。

以上。OL6 で 標準インストール以外の Python を使ってみる話でした。

0 件のコメント:

コメントを投稿