TensorFlow is an open source machine learning platform built by Google. It can run on CPU or GPU on different devices.
TensorFlow can be installed system-wide, in a Python virtual environment, as a Docker container, or using Anaconda.
In this tutorial, we will explain how to install TensorFlow in a Python virtual environment on Debian 10.
The virtual environment allows you to have several different isolated Python environments on the same machine and install a specific version of the module for each project without worrying about impacting your other projects.
Installing TensorFlow on Debian 10
The following sections provide step-by-step instructions for installing TensorFlow in a Python virtual environment on Debian 10.
1. Installing Python 3 and venv
Debian 10 Buster ships with Python 3.7.
To make sure Python 3 is installed on your system, enter:
The output should look like this:
The recommended way to create a virtual environment is using the venv module provided by the python3-venv package.
If the python3-venv package is not installed on your system, install it by typing:
sudo apt updatesudo apt install python3-venv
2. Creation of a virtual environment
Change to the directory where you store your Python 3 virtual environments. This can be your home directory or any directory where your user has read / write permissions.
Create a new directory for the TensorFlow project and switch to it:
mkdir my_tensorflowcd my_tensorflow
Inside the directory, enter the following command to create a virtual environment:
python3 -m venv venv
The above command creates a directory called venv which contains a copy of the Python binary, Pip package manager, Python standard library, and other supporting files.
You can use any name for the virtual environment.
To start using the virtual environment, you need to activate it by running the activate script:
Upon activation, the bin directory of the virtual environment will be added to the beginning of the $ PATH system variable. In addition, the shell prompt will change to show the name of the virtual environment you are in. In this example, this is (venv).
Installing TensorFlow requires pip version 19 or higher. Run the following command to update pip to the latest version:
pip install --upgrade pip
3. Installing TensorFlow
Now that we have created the virtual environment, the next step is to install the TensorFlow package.
There are several TensorFlow packages that can be installed from PyPI. Tensorflow only supports processors and is recommended for beginners.
If you have a dedicated NVIDIA GPU with CUDA 3.5 compute power or higher and want to take advantage of its computational power, instead of tensorflow, install the tensorflow-gpu package, which includes GPU support.
Enter the command below to install TensorFlow:
pip install --upgrade tensorflow
In a virtual environment, you can use pip instead of pip3 and python instead of python3.
Once the installation is complete, check this with the following command, which will display the TensorFlow version:
python -c 'import tensorflow as tf; print(tf.__version__)'
At the time of this writing, the latest stable version of TensorFlow 2.0.0 is:
The version printed on your terminal may differ from the version shown above.
That’s all. TensorFlow is installed on your Debian system.
If you’re new to TensorFlow, visit the TensorFlow Tutorials page to learn how to create your first ML app. You can also clone the TensorFlow Models or TensorFlow-examples repositories from Github, and explore and test the TensorFlow examples.
When you’re done with your work, run deactivate to deactivate the environment and return to your regular shell.
We showed you how to install TensorFlow pip in a Python virtual environment on Debian 10.
If you run into an issue or have feedback, please leave a comment below.