How to Install TensorFlow on Debian 9
3 min read
TensorFlow is a free and open-source platform for machine learning built by Google. It is used by a number of organizations including Twitter, PayPal, Intel, Lenovo, and Airbus.
TensorFlow can be installed system-wide, in a Python virtual environment, as a Docker container or with Anaconda. For learning purposes, it is best to install TensorFlow in a Python virtual environment. This way you can 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.
This tutorial will guide you through the process of installing TensorFlow on Debian 9.
Installing TensorFlow on Debian 9
The following sections provide a step by step instructions about how to install TensorFlow in a Python virtual environment on Debian 9.
1. Installing Python 3 and venv
By default, Debian 9 ships with Python 3.5. 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. Install the
python3-venv package that provides the
venv module by running the following command:
sudo apt install python3-venv
Once done we can proceed with the next step and create a virtual environment for our TensorFlow project.
2. Creating a Virtual Environment
Navigate to the directory in which you’d like to 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 cd into it:
From inside the directory, run the following command to create the virtual environment:
python3 -m venv venv
The command above will create a directory named
venv, which contains a copy of the Python binary, the Pip package manager
, the standard Python library and other supporting files. 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
. Also the shell’s prompt will change and it will show the name of the virtual environment you’re currently in. In this case 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.
pip install --upgrade tensorflow
If you have a dedicated NVIDIA GPU and want to take advantage of its processing power, instead of
tensorflow install the
tensorflow-gpu package which includes GPU support.
Within the virtual environment, you can use the command
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 2.0.0
Your TensorFlow version may be different from the version shown above.
If you are new to TensorFlow, visit the Get Started with TensorFlow 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.
In this tutorial, we have shown you how to install TensorFlow on Debian 9.
If you hit a problem or have feedback, leave a comment below.