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.
CentOS 7.0 python 2.7.5 (existing)
** 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 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)".
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.
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()
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()
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
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