[PYTHON] How to install TensorFlow on CentOS 7

Introduction

Install TensorFlow on CentOS7. There are many ways to create a Python execution environment, but all of them can be difficult if you are not familiar with Python. This time, I created this procedure with the aim of making it easy to install and work. This procedure has been confirmed on CentOS 7.2, but I think that it could be installed on CentOS 6 or CentOS 7.3 or later using the same procedure.

First of all, I want to keep Python that comes standard with CentOS untouched, so Create a Python virtual environment and install TensorFlow on it.

Install pyenv

Install pyenv, a tool for creating virtual Python environments. Please download pyenv from the official website below. https://github.com/pyenv/pyenv/releases This procedure uses the latest "pyenv-1.0.8" at the time.

Place the downloaded pyenv-1.0.8.zip in the user's home directory. Extract the zip and rename it.

cd
unzip pyenv-1.0.8.zip
mv pyenv-1.0.8 ~/.pyenv

Set the installation location in an environment variable.

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc

Installation of Anaconda

Install Anaconda, which is a set of Python and conda, a Python package management tool. The Python installed here is for Anaconda only, and the Python used in TensorFlow will be installed later.

pyenv install anaconda3-4.3.0
pyenv rehash
pyenv global anaconda3-4.3.0

Add Anaconda to your environment variables.

echo 'export PATH="$PYENV_ROOT/versions/anaconda3-4.3.0/bin/:$PATH"' >> ~/.bashrc
source ~/.bashrc

As a post-installation check, update conda itself to see which version of Pythono Anaconda uses.

conda update conda

python -V

This time, it was displayed as "Python 3.6.0 :: Anaconda 4.3.0 (64-bit)".

Python installation

Finally, install Python for TensorFlow. "Tensorflow" is the name of the Python virtual environment that you will create, so please use any name you like. Also, this time I would like to create an environment for Python 3.6.

conda create -n tensorflow python=3.6.0

Below is the command to enter the created virtual environment. It's the same Python 3.6.0, so it's hard to understand, but when you enter the virtual environment, the Python version changes.

source activate tensorflow

python -V

Install TensorFlow

Install TensorFlow for Python 3.6. Please check the official website below for the version of TensorFlow. https://www.tensorflow.org/install/install_linux#the_url_of_the_tensorflow_python_package

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp36-cp36m-linux_x86_64.whl
pip install --ignore-installed --upgrade $TF_BINARY_URL

This time, "Successfully installed appdirs-1.4.3 numpy-1.12.1 packaging-16.8 protobuf-3.2.0 pyparsing-2.2.0 setuptools-34.3.2 six-1.10.0 tensorflow-1.0.1 wheel-0.29.0" Was displayed.

Enter the Python console and check the operation.

python

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

I can't find TensorFlow! It is OK if "b'Hello, TensorFlow!'" Is displayed without any error. Exit the Python console with "Ctrl + d".

This completes the TensorFlow installation! If you want to enter the TensorFlow execution environment after the next login, Enter the virtual environment created by the following command. (The name was given when the environment was created.)

source activate tensorflow

The commands from the TensorFlow virtual environment are as follows.

source deactivate

Install numPy, OpenCV, pillow

From here, it is optional, but install OpenCV etc. which is necessary when you want to execute deep learning of image analysis system such as CNN with TensorFlow. Enter the created virtual environment and install numPy, OpenCV, pillow in order.

source activate tensorflow

conda install -c anaconda numpy=1.12.1
conda install -c menpo opencv3=3.1.0
conda install -c anaconda pillow=4.0.0

Enter the Python console and check the operation.

python

import numpy as np
import cv2
from PIL import Image

If there is no error, it is OK. Exit the Python console with "Ctrl + d".

Bonus (how to install Python 2.7)

Python 2.7 is still in active use, so let's install another version of Python. If you are in the 3.6 TensorFlow virtual environment you created earlier, exit it. Create a Python 2.7 series virtual environment with the name "tensorflow2".

conda create -n tensorflow2 python=2.7.13

Enter the virtual environment and make sure you have Python 2.7 installed.

source activate tensorflow2

python -V

Now install TensorFlow on Python 2.7 as well.

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
pip install --ignore-installed --upgrade $TF_BINARY_URL

Check the operation.

python

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

This completes the installation of TensorFlow with Python 2.7! You can install numPy, OpenCV and pillow with the same command as Python 3.6.

Recommended Posts

How to install TensorFlow on CentOS 7
How to install PyPy on CentOS
How to install Maven on CentOS
How to install Apache (httpd) on CentOS7
How to install Eclipse GlassFish 5.1.0 on CentOS 7
How to install Apache (httpd) on CentOS8
Steps to install MySQL 8.0 on CentOS 8.1
How to install mysql-connector-python on mac
Steps to install VirtualBox on CentOS
How to install graph-tool on macOS
How to install Git GUI and Gitk on CentOS
How to install pycrypto on Windows
How to install OpenCV on Mac
How to install Go on Ubuntu
How to install music 21 on windows
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
How to install aws-session-manager-plugin on Manajro Linux
How to install drobertadams / toggl-cli on Mac
[Kivy] How to install Kivy on Windows [Python]
How to install packages on Alpine Linux
How to install Anisble on Amazon Linux 2
How to switch mouse operations on CentOS
How to install richzhang / colorization on Windows 10
How to update security on CentOS Linux 8
How to install php7.4 on Linux (Ubuntu)
How to install NumPy on Raspberry Pi
How to install cx_Oracle on macOS Sierra
How to install python3 with docker centos
Install Tensorflow on Mac
Install TensorFlow on Ubuntu
Install Faiss on CentOS 7
How to install Python
How to install pip
How to install archlinux
Install numba on CentOS 7.2
How to install python
Install Python3.4 on CentOS 6.6
How to install BayesOpt
Install mecab-python on CentOS
Install Python 2.7.3 on CentOS 5.4
How to install Nbextensions
How to install Prover9
Install awscli on centos7
Install Chainer on CentOS 6.7
[2020 version] How to install Python3 on AWS EC2
How to install OpenCV on Jetson Nano Python
How to quickly install h5py on Windows 10 [Unofficial]
How to install OpenGM on OSX with macports
How to install Camunda Modeler on Manjaro Linux
[Python] How to install OpenCV on Anaconda [Windows]
How to install / verify graphviz on anaconda / windows10
[2020.8 latest] How to install Python
How to install Python [Windows]
Install Python 3.8 on CentOS 7 (SCL)
How to register on pypi
How to install mkl numpy
Install Chrome on CentOS 7 series
Install Python 3.8 on CentOS 8 (AppStream)
How to install Pelican blog
Install TensorFlow 1.15.0 on Raspberry Pi
How to install Linux on a 32bit UEFI PC