Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Install TensorFlow on Ubuntu 20.04 - DesignLinux

designlinux 0 Comments

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.

This tutorial explains how to install TensorFlow in a Python virtual environment on Ubuntu 20.04.

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 Ubuntu 20.04 #

Ubuntu 20.04 ships with Python 3.8 by default. You can verify that Python 3 is installed on your system by typing:

python3 -V

The output should look like this:

Python 3.8.2

The recommended way to create a virtual environment is by using the venv module, which is included in the python3-venv package.

To install the python3-venv package run the following command:

sudo apt install python3-venv python3-dev

Once the module is installed, you are ready to create a virtual environment for our TensorFlow project.

Navigate to the directory where you would 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:

mkdir my_tensorflowcd my_tensorflow

Within the directory, run the following command to create the virtual environment:

python3 -m venv venv
The second venv is the name of the virtual environment. You can use any name you want for the virtual environment.

The command above creates a directory named venv, that contains a copy of the Python binary, the Pip package manager, the standard Python library, and other supporting files.

To start using the virtual environment, activate it by running the activate script:

source venv/bin/activate

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 (venv).

TensorFlow installation requires pip version 19 or higher. Enter the following command to upgrade pip to the latest version:

pip install --upgrade pip

Now that the virtual environment is activated, it’s time 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 pip3 and python instead of python3.

That’s it! You have successfully installed TensorFlow, and you can start using it.

To verify the installation, run 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.2.0:

2.2.0

Your TensorFlow version may differ from the version shown here.

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.

Once you are done with your work, deactivate the environment by typing deactivate, and you will return to your normal shell.

deactivate

Conclusion #

We have shown you how to install TensorFlow inside a virtual environment on Ubuntu 20.04.

If you hit a problem or have feedback, leave a comment below.

python ubuntu

Related

Tags: python, ubuntu

How To Install Linux Mint 20 “Ulyana”

Prev Post

How to Install Apache Web Server on Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 515
  • 1,055,287

DesignLinux.com © All rights reserved

Go to mobile version