What to note: Install TensorFlow on Ubuntu (version python2.7)
Note Date: 2018-01-31
Install TensorFlow on Ubuntu (version python2.7)
My system environment:
- Ubuntu 16.04 LTS
- Python 2.7
- Python 3.5
Two versions of TensorFlow:
The TensorFlow is mainly installed in the following ways:
- Virtualenv
- Pip
- Docker
- Anaconda
- Source code Compilation
I use Pip to install, Pip is a Python package management system: PIP Install Packages recursive abbreviation
The format of the PIP installation Package command is as follows:
Pip Install package name
The format of the PIP Unload Package command is as follows:
Pip Uninstall Package name
I use the Virtualenv form of installation here, the following is the official installation documentation for TensorFlow:
Https://tensorflow.google.cn/install/install_linux
1. Install PYTHON-PIP, Python-dev and python-virtualenv, and I am installing the python2.7 version here:
$ sudo apt-get install python-pip python-dev python-virtualenv
2. Create a VIRTUALENV environment:
[[email protected]:~]$ virtualenv --system-site-packages tensorflowRunning virtualenv with interpreter /usr/bin/python2New python executable in /home/zero/tensorflow/bin/python2Also creating executable in /home/zero/tensorflow/bin/pythonInstalling setuptools, pkg_resources, pip, wheel...done.
3. Activate the VIRTUALENV environment:
[[email protected]:~]$ source ~/tensorflow/bin/activate(tensorflow) [[email protected]:~]$
4. Install PIP:
(tensorflow) [[email protected] ~]$ easy_install -U pip
5. Install TensorFlow, I install the CPU version here:
(tensorflow) [[email protected] ~]$ pip install --upgrade tensorflow
Tip: If your pip is installed slowly, it is because the default is to use a foreign source, we can change to a domestic source:
[[email protected] ~]$ vim .pip/pip.conf # 编辑为以下内容[global]index-url = http://pypi.douban.com/simpletrusted-host = pypi.douban.com #没有这句会包warningdisable-pip-version-check = true #版本不检查timeout = 120
Note: If the. pip/pip.conf is not created then you can.
6. After installation, enter the Python command line, import the TensorFlow package, and if there is no output, the installation is successful:
(tensorflow) [[email protected] ~]$ pythonPython 2.7.12 (default, Dec
Some other things to do:
Deactivate command to exit the virtual environment:
To delete a virtual environment, simply delete the generated directory:
[[email protected] ~]$ rm -rf tensorflow/[[email protected] ~]$
Above we demonstrated the installation of TensorFlow via Virtualenv, and then we will demonstrate the installation of TensorFlow by local PIP:
1. You need to install Pip and Dev First:
[[email protected] ~]$ sudo apt-get install python-pip python-dev
2. Then install with PIP:
[[email protected] ~]$ pip install tensorflow
3. After the installation is also entered into the Python command line, import the TensorFlow package, if there is no output on behalf of the successful installation:
[[email protected] ~]$ pythonPython 2.7.12 (default, Dec
This method is installed on the local system, and the previous installation method is installed in a virtual environment, each time you need to enter the virtual environment to use TensorFlow, installed on the local system is not required.
Uninstall TensorFlow using the following command:
sudo pip uninstall TensorFlow
We can use PIP to install some basic Python class libraries:
pip install numpypip install pandaspip install matplotlib
Write the first TensorFlow program: Hello World
Above we have installed TensorFlow, then we will write the first TensorFlow program: Hello World
1. Create the appropriate directory:
2. Edit a python file:
[[email protected] ~/TensorFlow/HelloWorld]$ vi helloworld.py # 内容如下# -*- coding: UTF-8 -*-# 引入 Tensorflow 库import tensorflow as tf# 创建一个常量 Operation (操作)hw = tf.constant("Hello Wolrd!")# 启动一个Tensorflow 的 Session(会话)sess = tf.Session()# 运行 Graph (计算图)print sess.run(hw)# 关闭 Session(会话)sess.close()
3. Run the file to see if the output is normal:
As above, you can see Hello wolrd! The output was normal, and some hints were printed, so that's when our first TensorFlow program was written.
Install TensorFlow on Ubuntu (version python2.7)