LoginSignup
6
12

More than 5 years have passed since last update.

CentOS7にTensorFlowをインストールする

Posted at

※この記事は、2016年8月に他のブログで書いた記事をQiitaに移行したものです。


色々あって、ディープラーニングの勉強を始めることになりました。といっても、TensorFlow(Googleのディープラーニングフレームワーク)を動かしてみるのが、目先の目標です。

本格的にやるなら、高度な数学の知識も必要そうだし、どうしようかなーというところです。

やりたいことが多すぎて、優先順位づけが難しいですね。

早速、環境を整えたので、その際の手順を載せます。

Window10 + Vagrant + Virtualbox + CentOS7 にTensorFlowをインストールしました。

Pythonのバージョンを確認

2.7系と3系で、インストールの仕方が変わります。

[vagrant@localhost ~]$ python --version
Python 2.7.5

Pythonの必要なモジュールをインストール

Download and Setup(公式サイト)では、apt-getコマンドになっているが、CentOSではyumを使う。

apt-getコマンドは、Debian系のディストリビューション(DebianやUbuntu)のパッケージ管理システムであるAPT(Advanced Package Tool)ライブラリを利用してパッケージを操作・管理するコマンドです。

CentOSやFedoraのパッケージ管理には「yumコマンド」を利用します。

参考サイト : Linuxコマンド【 apt-get 】パッケージの操作・管理 - Linux入門 - Webkaru

実際にインストールしてみる。

[vagrant@localhost ~]$ yum -y install python-pip python-dev
読み込んだプラグイン:fastestmirror
このコマンドを実行するには root である必要があります。
[vagrant@localhost ~]$ sudo yum -y install python-pip python-dev
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.fairway.ne.jp
 * epel: mirror.premi.st
 * extras: mirror.fairway.ne.jp
 * updates: centosx4.centos.org
パッケージ <span style="color: #ff0000;">python-dev</span> は利用できません。
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ python-pip.noarch 0:7.1.0-1.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

========================================================================================================================================================================
 Package                                   アーキテクチャー                      バージョン                                   リポジトリー                         容量
========================================================================================================================================================================
インストール中:
 python-pip                                noarch                                7.1.0-1.el7                                  epel                                1.5 M

トランザクションの要約
========================================================================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 1.5 M
インストール容量: 6.6 M
Downloading packages:
python-pip-7.1.0-1.el7.noarch.rpm                                                                                                                | 1.5 MB  00:01:18
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : python-pip-7.1.0-1.el7.noarch                                                                                                           1/1
  検証中                  : python-pip-7.1.0-1.el7.noarch                                                                                                           1/1

インストール:
  python-pip.noarch 0:7.1.0-1.el7

完了しました!

python-pipはインストールできたが、python-devがインストールできない

yum searchで、64bit用にpython-devel.x86_64が使えると分かる

[vagrant@localhost ~]$ yum search python | grep -i devel
dbus-python-devel.i686 : Libraries and headers for dbus-python
dbus-python-devel.x86_64 : Libraries and headers for dbus-python
gstreamer-python-devel.i686 : Headers for developing programs that will use
gstreamer-python-devel.x86_64 : Headers for developing programs that will use
nemo-python-devel.x86_64 : Python bindings for Nemo
ovirt-engine-sdk-python.noarch : oVirt Engine Software Development Kit (Python)
python-behave.noarch : Tools for the behavior-driven development, Python style
python-caja-devel.x86_64 : Python bindings for Caja
python-cherrypy.noarch : Pythonic, object-oriented web development framework
python-cherrypy2.noarch : Pythonic, object-oriented web development framework
python-devel.x86_64 : The libraries and header files needed for Python
                    : development
python-greenlet-devel.x86_64 : C development headers for python-greenlet
python-nbxmpp-doc.noarch : Developer documentation for python-nbxmpp
python-pillow-devel.i686 : Development files for python-pillow
python-pillow-devel.x86_64 : Development files for python-pillow
python-pyside-devel.x86_64 : Development files for python-pyside
python-tools.x86_64 : A collection of development tools included with Python
python-werkzeug.noarch : The Swiss Army knife of Python web development
python2-ola.noarch : Python Development files for OLA
                             : developed at OSRF
python34-devel.x86_64 : Libraries and header files needed for Python 3
                      : development
wxPython-devel.x86_64 : Development files for wxPython add-on modules
xapian-bindings-python.x86_64 : Files needed for developing Python scripts which
TurboGears.noarch : Back-to-front web development in Python
edk2-tools-python.noarch : EFI Development Kit II Tools
gnome-python2-devel.x86_64 : Development files for building add-on libraries
hawkey-devel.i686 : A Library providing simplified C and Python API to libsolv
hawkey-devel.x86_64 : A Library providing simplified C and Python API to libsolv
kobo.noarch : Python modules for tools development
pygtksourceview-devel.x86_64 : Development files for using pygtksourceview in
pyldb-devel.i686 : Development files for the Python bindings for the LDB library
pyldb-devel.x86_64 : Development files for the Python bindings for the LDB
python-igraph-devel.x86_64 : Development files for igraph
python-pycxx-devel.noarch : PyCXX header and source files
python-strainer.noarch : Tools to allow developers to cleanup web serialization
python-zc-buildout.noarch : System for managing development buildouts
python2-clint.noarch : A set of awesome tools for developing commandline
qscintilla-python-devel.noarch : Development files for QScintilla PyQt4 bindings
redhat-support-lib-python.noarch : Red Hat Support Software Development Library
sip-devel.i686 : Files needed to generate Python bindings for any C++ class
sip-devel.x86_64 : Files needed to generate Python bindings for any C++ class
spyder.noarch : Scientific Python Development Environment

参考サイト : python 2.7 - How to install python27-devel on Centos 6.5 - Stack Overflow

python-devの代わりにpython-devel.x86_64をインストールする。

[vagrant@localhost ~]$ sudo yum -y install python-devel.x86_64
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.fairway.ne.jp
 * epel: mirror.premi.st
 * extras: mirror.fairway.ne.jp
 * updates: centosx4.centos.org
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ python-devel.x86_64 0:2.7.5-34.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

========================================================================================================================================================================
 Package                                    アーキテクチャー                     バージョン                                    リポジトリー                        容量
========================================================================================================================================================================
インストール中:
 python-devel                               x86_64                               2.7.5-34.el7                                  base                               391 k

トランザクションの要約
========================================================================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 391 k
インストール容量: 1.0 M
Downloading packages:
python-devel-2.7.5-34.el7.x86_64.rpm                                                                                                             | 391 kB  00:00:13
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : python-devel-2.7.5-34.el7.x86_64                                                                                                        1/1
  検証中                  : python-devel-2.7.5-34.el7.x86_64                                                                                                        1/1

インストール:
  python-devel.x86_64 0:2.7.5-34.el7

完了しました!

TensorFlowのインストール

[vagrant@localhost ~]$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting tensorflow==0.9.0 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
  Downloading https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl (27.6MB)
    100% |????????????????????????????????| 27.6MB 11kB/s
Collecting six>=1.10.0 (from tensorflow==0.9.0)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting protobuf==3.0.0b2 (from tensorflow==0.9.0)
  Downloading protobuf-3.0.0b2-py2.py3-none-any.whl (326kB)
    100% |????????????????????????????????| 327kB 95kB/s
Collecting wheel (from tensorflow==0.9.0)
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |????????????????????????????????| 69kB 110kB/s
Collecting numpy>=1.8.2 (from tensorflow==0.9.0)
  Downloading numpy-1.11.1.zip (4.7MB)
    100% |????????????????????????????????| 4.7MB 53kB/s
Collecting setuptools (from protobuf==3.0.0b2->tensorflow==0.9.0)
  Downloading setuptools-25.1.0-py2.py3-none-any.whl (442kB)
    100% |????????????????????????????????| 446kB 60kB/s
Installing collected packages: six, setuptools, protobuf, wheel, numpy, tensorflow
  Found existing installation: setuptools 0.9.8
    Uninstalling setuptools-0.9.8:
      Successfully uninstalled setuptools-0.9.8
  Running setup.py install for numpy
Successfully installed numpy-1.11.1 protobuf-3.0.0b2 setuptools-25.1.0 six-1.10.0 tensorflow-0.9.0 wheel-0.29.0

TensorFlowのテスト

[vagrant@localhost ~]$ python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a+b))
42
>>>

参考サイト : Download and Setup

参考サイト

6
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
12