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, 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
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)".
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 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
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".
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