How to Upgrade or Downgrade TensorFlow

September 20, 2021

Introduction

TensorFlow is one of the best machine learning libraries for Python. There are various TensorFlow versions with different capabilities. Additionally, certain releases are only compatible with specific Python versions.

This article explains how to upgrade or downgrade TensorFlow.

How to Upgrade or Downgrade TensorFlow

Prerequisites

Note: Depending on the Python version, only specific TensorFlow releases are available:

  • Python 3.9 works with TensorFlow 2.5 and later releases.
  • Python 3.8 works with TensorFlow 2.2 and later releases.

How to Upgrade TensorFlow

To upgrade TensorFlow to a newer version:

1. Open the terminal (CTRL+ALT+T).

2. Check the currently installed TensorFlow version:

pip3 show tensorflow
Check TensorFlow version before upgrade

The command shows information about the package, including the version.

3. Upgrade TensorFlow to a newer version with:

pip3 install --upgrade tensorflow==<version>
Upgrade TensorFlow with pip install command

Make sure to select a version compatible with your Python release. If the release is incompatible, the version will not install. For the notebook environment, use the following command and restart the kernel after completion:

!pip install --upgrade tensorflow==<version>

The install automatically removes the old version along with the dependencies and installs the newer upgrade.

4. Lastly, check the upgraded version by running:

pip3 show tensorflow
Check TensorFlow version after upgrade

How to Downgrade TensorFlow

The best practice for TensorFlow downgrade is to use the latest version of Python and TensorFlow. Older versions have vulnerability issues, so be cautious when downgrading.

1. Check the currently installed TensorFlow version:

pip3 show tensorflow

2. Downgrade TensorFlow to a lower version by running:

pip3 install --upgrade tensorflow==<version>

Set the version to a lower number than the currently installed release. When choosing, make sure the version is compatible with the Python release.

If you are using a Notebook environment, run the following command and restart the kernel when the installation completes:

!pip install --upgrade tensorflow==<version>

The upgrade automatically removes the existing TensorFlow and installs the stated version.

3. Finally, use the pip show command to confirm the correct TensorFlow version installed:

pip3 show tensorflow

Note: Deploy TensorFlow on a Bare Metal Cloud server instance to ensure that your TensorFlow workloads always have enough resources for optimal performance.

Conclusion

The pip package manager offers a simple method to upgrade or downgrade TensorFlow, regardless of environment.

Next, learn why GPUs are necessary for Deep Learning.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP who is passionate about programming. Her background in Electrical Engineering and Computing combined with her teaching experience give her the ability to easily explain complex technical concepts through her content.
Next you should read
How To Check TensorFlow Version
March 3, 2021

TensorFlow can be installed in many ways and there are many different versions and builds available. Learn how to check which version is installed on your machine.
Read more
How to Install Keras With TensorFlow Backend on Linux
August 24, 2020

Follow the step by step instructions to learn how to prepare your system for the installation of Keras and TensorFlow. We also talk about...
Read more
How to Install TensorFlow GPU on Ubuntu 18.04
November 29, 2022

Designed to simplify the process of implementing machine-learning models, TensorFlow is Google’s open-source platform for machine learning. This article shows how to...
Read more
How to Install and Use TensorFlow on CentOS 7
October 8, 2019

TensorFlow is Google’s open-source platform for machine learning. It was designed to simplify the process of implementing machine-learning models. This article shows how to...
Read more