TensorFlow is an open-source platform for machine learning built by Google. It can runs on CPU or GPU on different devices.
TensorFlow can be installed system-wide, in a Python virtual environment, as a Docker container, or with Anaconda.
In this tutorial, we’ll explain how to install TensorFlow in a Python virtual environment on Debian 10.
A virtual environment allows you to have multiple different isolated Python environments on a single computer and install a specific version of a module on a per-project basis, without worrying that it will affect your other Projects.
Installing TensorFlow on Debian 10
The following sections provide a step by step instructions about how to install TensorFlow in a Python virtual environment on Debian 10.
1. Installing Python 3 and venv
Debian 10, Buster ships with Python 3.7.
To verify that Python 3 is installed on your system, type:
The output should look like this:
The recommended way to create a virtual environment is by using the
venv module, which is provided by the
python3-venv package is not installed on your system, install it by entering:
sudo apt update
sudo apt install python3-venv
2. Creating a Virtual Environment
Navigate to the directory in which you store your Python 3 virtual environments. It can be your home directory or any other directory where your user has read and write permissions.
Create a new directory for the TensorFlow project and switch to it:
From inside the directory, enter the following command to create the virtual environment:
python3 -m venv venv
The command above creates a directory named
venv, which contains a copy of the Python binary, the Pip package manager, the standard Python library, and other supporting files.
You can use any name you like for the virtual environment.
To start using the virtual environment, you’ll need to activate it by running the
Once activated, the virtual environment’s bin directory will be added at the beginning of the system
$PATH variable. Also, the shell’s prompt will change, and it will show the name of the virtual environment you’re currently in. In this example, that is
TensorFlow installation requires
pip version 19 or higher. Run the following command to upgrade
pip to the latest version:
pip install --upgrade pip
3. Installing TensorFlow
Now that we’ve created a virtual environment, the next step is to install the TensorFlow package.
There are several TensorFlow packages that can be installed from PyPI. The
tensorflow package supports only CPUs, and it is recommended for novice users.
If you have a dedicated NVIDIA GPU with CUDA compute capability 3.5 or higher and want to take advantage of its processing power, instead of
tensorflow install the
tensorflow-gpu package which includes GPU support.
Enter the command below to install TensorFlow:
pip install --upgrade tensorflow
Within the virtual environment, you can use
pip instead of
python instead of
Once the installation is complete, verify it with the following command which will print the TensorFlow version:
python -c 'import tensorflow as tf; print(tf.__version__)'
At the time of writing this article, the latest stable version of TensorFlow is
The version printed on your terminal may be different from the version shown above.
That’s it. TensorFlow is installed on your Debian system.
If you are new to TensorFlow, visit the TensorFlow tutorials page and learn how to build your first ML application. You can also clone the TensorFlow Models or TensorFlow-Examples repositories from Github and explore and test the TensorFlow examples.
When you are done with your work, type
deactivate to deactivate the environment and return to your normal shell.
We have shown you how to install TensorFlow with
pip inside a Python virtual environment on Debian 10.
If you hit a problem or have feedback, leave a comment below.