In this article you will learn how to install and use TensorFlow on Ubuntu 16.04 18.04 or. Consider the correct installation TensorFlow in a virtual environment or Python in Docker container. Principles of installation work in Ubuntu and Debian.
It is a complex platform with open source code designed for machine learning. For example, TensorFlow can be used when constructing and training neural networks. Thanks to a comprehensive and flexible system of tools, libraries, and community resources.
TensorFlow allows developers to use the latest machine learning technology. It is now easier to create and deploy applications based on machine learning. Search giant Google has developed this platform for search ranking in the system of machine learning. TensorFlow available in the virtual environment or Python in Docker container. You can also install with Anaconda. For installation, you will need to have installed Python 3.3 and above, as well as Git.
TensorFlow installing Ubuntu in a virtual environment with Python 3
Step 1. Update package list
Make sure that the APT index default updated. To do this, run the following command:
sudo apt update
sudo apt upgrade-y
Step 2. Python Installation
Install Python 3 and Python venv, using the following commands.
sudo apt install python3
sudo apt install python3-pip
sudo apt install python3-venv
After installing Python 3 check what version of Python is installed by typing:
Step 3. The virtual environment
You need to create a virtual Python environment named tenorflow_env. To do this, type the following command:
python3 -m venv my_tensorflow
This command will create a new directory my_tensorflow. It will be all packages that you install until you have activated Python environment.
Now to activate the virtual environment. Otherwise we will not be able to use it:
Step 4. Installation tensorflow
Now just to set TensorFlow in a virtual environment by running the command to install and upgrade to the latest version of the platform:
pip3 install --upgrade tensorflow
To verify correct installation and removal of the terminal version TensorFlow, just run the following command:
python -c 'import tensorflow as tf; print(tf.__version__)'
If everything matches with the image in the screenshot, so you did the right thing.
Installation TensorFlow Docker
Another way to install TensorFlow installation in a docker container. Of course, you first need to install Docker in Ubuntu itself. Then upload the image file TensorFlow in a Docker container using the following steps. You first need to upload the image to Docker TensorFlow:
sudo docker pull tensorflow/tensorflow
After loading the image, run it with the command:
docker run -it-p 8888:8888 tensorflow/tensorflow
More information about installing TensorFlow in Docker you will find on the official website.
Installation via pip TensorFlow with 3
There is a way of installing it using the package Manager pip3. To do this, type the following command:
pip3 install tensorflow
Create a simple program TensorFlow
After completing the installation, check the condition of TensorFlow. You can write a simple “Hello world” code testTensorFlow.py using the text editor vim. Enter the command below:
import tensorflow as tf
hello = tf.constant("Hello, world!")
session = tf.Session()
Next you need to save and close the file. Then run the Python file with the following command:
Now you know how установитьTensorFlow 18.04 in Ubuntu or Debian. As you can see, it’s not very difficult and you have a number of ways. For more information check the official website.