Choose a different version or distribution
Introduction
Before we begin talking about how to install TensorFlow on Debian 10, let's briefly understand – What is TensorFlow?
TensorFlow is a machine learning open-source platform developed by Google. It can run on CPU or GPU on various devices.
TensorFlow can be installed via Anaconda, a virtual Python environment, a Docker container, or a system-wide installation.
A virtual environment enables you to install a particular version of a module for each project without worrying that it would have an impact on your other Projects, and to have numerous distinct isolated Python environments on a single computer.
In this tutorial, you will install TensorFlow on Debian 10.
Installing TensorFlow on Debian 10
The steps to install TensorFlow in a Python virtual environment on Debian 10 are detailed below:
1. Installing Python 3 and venv
Python 3.7 is included with Debian 10, Buster.
Type the following to make sure Python 3 is installed on your system:
python3 --version
You will get an output like below:
Output
Python 3.7.3
The venv
module, offered by the python3-venv
package, is the suggested method for creating a virtual environment.
Install the python3-venv
package if it is not already there on your computer by typing:
sudo apt update
sudo apt install python3-venv
2. Creating a Virtual Environment
Go to the location where your Python 3 virtual environments are stored. Your home directory or any other directory where your user has read and write permissions can serve as this location.
Make a new directory for the TensorFlow project and switch to it:
mkdir my_tensorflow
cd my_tensorflow
To create the virtual environment, type the following command from within the directory:
python3 -m venv venv
A copy of the Python binary, the Pip package manager, the default Python library, and other supporting files are all created in the directory venv
by the aforementioned command.
The virtual environment can be given whatever name you prefer.
You must run the activate
script in order to activate the virtual environment before you can use it:
source venv/bin/activate
Once activated, the system $PATH
variable will have the bin directory of the virtual environment appended to it. The name of the virtual environment you are in will also be displayed in a prompt in the shell. In this case, that is (venv)
.
pip
version 19 or higher is required for TensorFlow installation. To get the most recent version of pip
, enter the following command:
pip install --upgrade pip
3. Installing TensorFlow
The next step is to install the TensorFlow package now that we have established a virtual environment.
Several TensorFlow packages are available for installation from PyPI. Only CPUs are supported by the tensorflow
package, and it is recommended for new users.
Install the tensorflow-gpu
package, which adds GPU support, in place of tensorflow
if you want to use the processing power of a dedicated NVIDIA GPU with CUDA compute capability 3.5 or above.
To install TensorFlow, run the command listed below:
pip install --upgrade tensorflow
The next line will print the TensorFlow version, so use it to confirm that the installation was successful:
python -c 'import tensorflow as tf; print(tf.__version__)'
The most recent stable version of TensorFlow is 2.0.0
as of the time of writing.
Output
2.0.0
It is possible that the version printed on your terminal differs from the one above.
All done. TensorFlow is successfully installed on your Debian system.
Learn how to create your first machine learning application on the TensorFlow tutorials page if you are new to the software. To explore and test the TensorFlow examples, you may also clone the TensorFlow Models or TensorFlow-Examples repositories from GitHub.
When you are finished, type deactivate
to deactivate the environment and go back to your regular shell.
deactivate
Conclusion
You now know how to install TensorFlow with pip
inside a Python virtual environment on Debian 10.
If you have any queries, feel free to post a comment below, and we'll be happy to answer them.