The first artificial intelligence. Tensorflow on CentOS7.0. Built separately for python3.5 series and python2.7 series with virtualenv.

Overview

In order to switch the python version of Tensorflow and use it, try making it with python 2.7 series and python 3.5 series respectively.

environment

CentOS 7.0 python 2.7.5 (existing)

Advance preparation

** yum update **

yum update -y

Bulk install development related tools with yum group install.

# yum groupinstall "Development Tools"

** Install python3.5.2 **

# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
# cd Python-3.5.2
# ./configure --with-threads
# make altinstall
# cd

The reason why I didn't use make install is as follows.

** Install pip **

# wget https://bootstrap.pypa.io/get-pip.py
# python get-pip.py

Update after installing pip.

# pip -V
# pip install --upgrade pip

If the pip command does not work properly, the path does not pass, so check the location of pip with the following command and add the path.

# which pip

Please refer to other people's pages for adding paths.

Normal edition (reference): How to check and set the Linux path (PATH): Add path http://blog.96q.org/2008/03/21/path-setting-method/

Advanced (reference): Delete only a specific path from $ PATH http://qiita.com/ironsand/items/10e28d7589298090ec23

** Clone pyenv and pyenv-virtualenv ** As a side note, install pyenv-virtualenvwrapper as well.

# git clone https://github.com/yyuu/pyenv.git ~/.pyenv
# git clone git://github.com/yyuu/pyenv-virtualenv.git ./.pyenv/plugins/pyenv-virtualenv
# git clone https://github.com/yyuu/pyenv-virtualenvwrapper.git ./.pyenv/plugins/pyenv-virtualenvwrapper

Then add the path.

# vi ~/.bashrc

# ~/.Add the following to bashrc at the end
export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

For .bashrc and .bash_profile, I referred to the following.

Reference: Really correct use of .bashrc and .bash_profile http://qiita.com/magicant/items/d3bb7ea1192e63fba850

Check if the pass passed

# source ~/.bashrc
# echo $PATH

** Update git ** Go to ~ / .pyenv and make sure you have git and update it. When the update is complete, you will be returned to your home.

# cd ~/.pyenv
# ls -a
# git pull origin
# cd

** Check pyenv environment ** You can see that only system currently exists.

# pyenv versions
* system (set by /root/.pyenv/version)

Next, list what you can install with pyenv.

# pyenv install --list
Available versions:
  2.1.3
  2.2.3
  2.3.7
  2.4
  2.4.1
・
・
(Omitted)
・
・
  stackless-3.2.2
  stackless-3.2.5
  stackless-3.3-dev
  stackless-3.3.5
  stackless-3.4.1

You can see that various versions can be installed.

Install python3.5 series with pyenv

Install python3.5 series and python2.7 series, and set so that the version can be switched for each environment. This time, I will install python3.5.2.

# pyenv install 3.5.2
#Uninstall example
# pyenv uninstall 3.5.2

After installation, rehash and check.

# pyenv rehash
# pyenv versions
* system (set by /root/.pyenv/version)
  3.5.2

If 3.5.2 is displayed, the installation is complete. Next, install python2.7 series. If you do not install python2.7 series, please jump to "Separate Tensorflow python environment using pyenv-virtualenv (python3.5 series)".

Installation of pytho2.7 series with pyenv

Install python2.7 series.

# pyenv install 2.7.11

Installing Python-2.7.11...
Installed Python-2.7.11 to /root/.pyenv/versions/2.7.11

Once installed, let's rehash and check.

# pyenv rehash
# pyenv versions
* system (set by /root/.pyenv/version)
  2.7.11
  3.5.2

I have installed python2.7.11.

Separate Tensorflow python environment using pyenv-virtualenv (python3.5 series)

Create an environment where Tensorflow can be used with python3.5 series with virtualenv.

First, create a directory to separate the environment.

# mkdir tensorflow352

I hope the directory name will tell you which version of python you are using. Build a virtual environment with pyenv-virtualenv.

# cd tensorflow352
# pyenv virtualenv 3.5.2 tensorflow352
# pyenv rehash
# pyenv local tensorflow352

Check if the environment has been created.

# pyenv versions
  system
  2.7.11
  3.5.2
  3.5.2/envs/tensorflow352
  anaconda3-4.1.0
* tensorflow352 (set by /root/tensorflow352/.python-version)

I was able to confirm it at the bottom.

Also check the python version.

# python -V
Python 3.5.2

** Pip version upgrade ** Next, install tensorflow, but before that, upgrade pip. If you do not upgrade, you will get angry when installing Tensorflow. The current folder is in "tensorflow352".

# pwd
/root/tensorflow352

# pip install --upgrade pip

Collecting pip
  Using cached pip-8.1.2-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
      Successfully uninstalled pip-8.1.1
Successfully installed pip-8.1.2

Install Tensorflow.

# pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp35-cp35m-linux_x86_64.whl

Let's check if Tensorflow can be used.

# python

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 8
I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 8
>>> print(sess.run(hello))
Hello, TensorFlow!

It worked fine. Quit python.

>>> exit()

Installation of Tensorflow (python2.7 series)

Switch the python environment to 2.7 series with pyenv.

# cd
# pyenv global 2.7.11
# pyenv versions
  system
* 2.7.11 (set by /root/.pyenv/version)
  3.5.2
  3.5.2/envs/tensorflow352
  anaconda3-4.1.0
  tensorflow352

(*) Mark has moved to 2.7.11.

I was able to confirm that it was switched.

Also check the python version.

# python -V
Python 2.7.11

Next, create an environment for installing Tensorflow with python2.7 series.

# mkdir tensorflow2711
# pyenv virtualenv 2.7.11 tensorflow2711

Check if the environment has been created.

# pyenv versions
  system
* 2.7.11 (set by /root/.pyenv/version)
  2.7.11/envs/tensorflow2711
  3.5.2
  3.5.2/envs/tensorflow352
  anaconda3-4.1.0
  tensorflow2711
  tensorflow352

confirmed. Let's check if python2.7.11 is installed.

# cd tensorflow2711
# python -V
Python 2.7.11

Next, install tensorflow. Switch the environment to "tensorflow2711" and install Tensorflow.

# pyenv local tensorflow2711
# pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp27-none-linux_x86_64.whl

Let's check if Tensorflow can be used.

# python

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 8
I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 8
>>> print(sess.run(hello))
Hello, TensorFlow!

It worked fine. Quit python.

>>> exit()

What to do if system is not restored even if you select system in global of pyenv

I was also addicted to it. Thank you very much.

# rm ~/.python-version

Reference: Does not switch with pyenv global! http://qiita.com/1234224576/items/11ad3509fe4b0a9a33ed

virtualenv "global" and "local"

When switching the python environment, this "global" and "local" are used. For example, when you want to switch the Tensorflow python environment for each directory like this time, specify it as "pyenv local tensorflow352" in the corresponding directory. Then, when you return to the current directory with "cd", you can automatically exit from the previous environment.

[root]# pyenv versions
* system (set by /root/.pyenv/version)
  2.7.11
  2.7.11/envs/tensorflow2711
  3.5.2
  3.5.2/envs/tensorflow352
  tensorflow2711
  tensorflow352

[root]# cd tensorflow352                         <--Move to tensorflow352
[root tensorflow352]# pyenv local tensorflow352  <--switching
(tensorflow352) [root tensorflow352]# cd         <--Occasionally(tensorflow352)Attach
[root]# cd tensorflow352                         <--When you exit the directory(tensorflow352)Will come off automatically
(tensorflow352) [root tensorflow352]#            <--Automatically when you enter next(tensorflow352)Enter the environment of

If you find any mistakes or unnecessary work, please let us know.

Recommended Posts

The first artificial intelligence. Tensorflow on CentOS7.0. Built separately for python3.5 series and python2.7 series with virtualenv.
The first artificial intelligence. Challenge web output with python. ~ Flask introduction
A memo with Python2.7 and Python3 on CentOS
Initial settings for using Python3.8 and pip on CentOS8
I tried Python on Mac for the first time.
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
I tried python on heroku for the first time
Information for controlling the motor with Python on RaspberryPi
Building a python environment for artificial intelligence (Chainer / TensorFlow / CSLAIER)
The first artificial intelligence. How to check the version of Tensorflow installed.
See python for the first time
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
Work memo to migrate and update Python 2 series scripts on the cloud to 3 series
Put MeCab binding for Python with pip on Windows, mac and Linux
Impressions and memorandums when working with VS code for the first time
Read the file with python and delete the line breaks [Notes on reading the file]
Compare nighttime and daytime returns on the Nikkei Stock Average with python
I measured the speed of list comprehension, for and while with python2.7.
I tried tensorflow for the first time
Intuitive explanation that does not rely on mathematical formulas for the Monty Hall problem and simulation with Python
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Download files on the web with Python
MongoDB for the first time in Python
Clean python environment with pythonz and virtualenv
Build a flask app made with tensorflow and dlib to work on centos7
The first artificial intelligence. I wanted to try natural language processing, so I will try morphological analysis using MeCab with python3.
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Introduction to Artificial Intelligence with Python 1 "Genetic Algorithm-Theory-"
Introduction to Artificial Intelligence with Python 2 "Genetic Algorithm-Practice-"
Causal reasoning and causal search with Python (for beginners)
Building a python environment with virtualenv and direnv
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
Build a python environment with ansible on centos6
Specify the Python executable to use with virtualenv
[Ansible] Install dnf on Centos7 with Python3 interpreter
Use logger with Python for the time being
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
I tried python programming for the first time.
Introduction to Python with Atom (on the way)
Commands for creating a python3 environment with virtualenv
Solving the Lorenz 96 model with Julia and Python
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
Archive and compress the entire directory with python
Installing TensorFlow on Windows Easy for Python beginners
Make Python built with jhbuild work on OSX
Install Python and libraries for Python on MacOS Catalina
Automate background removal for the latest portraits in a directory with Python and API
The first step of machine learning ~ For those who want to implement with python ~
Build API server for checking the operation of front implementation with python3 and Flask
[CGI] Run the Python program on the server with Vue.js + axios and get the output data
Until you can install blender and run it with python for the time being