雑木林

頭の中の整理と忘れないための確認メモ

CentOS7でpython3をepelから入れる

CentOS7はPython 2.7系が入っており、今からpythonで何かするときに色々と不便です。
これまでpython3系はIUS Community Projectのリポジトリから入れるのが鉄板でしたが、
epelにもpython36が来てたので確認してみました。
(3.4は前からあったけどvenvとか上手く動かなかくて挫折した記憶があります。)

パッケージ情報はこんな感じ。

# yum info python36
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.qoxy.com
 * epel: ftp.jaist.ac.jp
 * extras: mirror.qoxy.com
 * ius: ius.mirror.constant.com
 * updates: mirror.qoxy.com
利用可能なパッケージ
名前                : python36
アーキテクチャー    : x86_64
バージョン          : 3.6.6
リリース            : 1.el7
容量                : 66 k
リポジトリー        : epel/x86_64
要約                : Interpreter of the Python programming language
URL                 : https://www.python.org/
ライセンス          : Python
説明                : Python is an accessible, high-level, dynamically typed, interpreted programming
                    : language, designed with an emphasis on code readability.
                    : It includes an extensive standard library, and has a vast ecosystem of
                    : third-party libraries.
                    :
                    : The python36 package provides the "python3" executable: the reference
                    : interpreter for the Python language, version 3.
                    : The majority of its standard library is provided in the python36-libs package,
                    : which should be installed automatically along with python36.
                    : The remaining parts of the Python standard library are broken out into the
                    : python36-tkinter and python36-test packages, which may need to be installed
                    : separately.
                    :
                    : Documentation for Python is provided in the python36-docs package.
                    :
                    : Packages containing additional libraries for Python are generally named with
                    : the "python36-" prefix.

とりあえずインストール

# yum install python36 python36-devel python36-libs
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
...

完了しました!

# python36 --version
Python 3.6.6

pipを入れてみます。

# python3 -m ensurepip
Looking in links: /tmp/tmpy8of2iuk
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1

# pip3 install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0

# pip3 list
Package    Version
---------- -------
pip        18.0
setuptools 39.0.1

venvも使えました。

# python36 -m venv testenv
# source testenv/bin/activate

(testenv) # pip -V
pip 10.0.1 from /root/testenv/lib64/python3.6/site-packages/pip (python 3.6)
(testenv) # pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0

(testenv) # pip list
Package    Version
---------- -------
pip        18.0
setuptools 39.0.1
(testenv) # pip install numpy
Collecting numpy
  Using cached https://files.pythonhosted.org/packages/fe/94/7049fed8373c52839c8cde619acaf2c9b83082b935e5aa8c0fa27a4a8bcc/numpy-1.15.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy
Successfully installed numpy-1.15.1

(testenv) # deactivate
#

しばらく使ってみようと思います。

2019/05/01 追記  virtualenvwrapperを使う場合はこんな感じ

# pip3 install virtualenvwrapper
cat << EOS >> /etc/profile
# for virtualenvwrapper
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/bin/virtualenvwrapper.sh
fi
EOS