How To Check TensorFlow Version

Introduction

TensorFlow is one of the most prominent machine learning packages. Knowing which version is on the system is vital as different builds have different options. There are multiple ways to check the TensorFlow version depending on the installation method.

This article shows how to check the TensorFlow version in six different ways.

How To Check TensorFlow Version

Prerequisites

Note: The recommended version is Python 3. Follow one of our guides on installing Python 3: How to install Python 3 on CentOS 7, How to install Python 3 on CentOS 8, How to install Python 3 on Ubuntu, How to install Python on Windows.

Check TensorFlow Version in Python

The simplest way to check the TensorFlow version is through a Python IDE or code editor. The library has built-in methods for displaying basic information.

To print the TensorFlow version in Python, enter:

import tensorflow as tf
print(tf.__version__)

TensorFlow Newer Versions

The TensorFlow 2.x versions provide a method for printing the TensorFlow version.

To check which one is on your system, use:

import tensorflow as tf
print(tf.version.VERSION)

TensorFlow Older Versions

TensorFlow 1.x has a slightly different method for checking the version of the library. Print the version for older TensorFlow builds in Python by running:

import tensorflow as tf
print(tf.VERSION)

Check TensorFlow Version in CLI

Display the TensorFlow version through Python invocation in the CLI with the python command. Using the -c option executes code.

If your machine has multiple instances of Python installed, use the python<version> command.

Check TensorFlow Version in Linux Terminal

Print the TensorFlow version in the terminal by running:

python -c 'import tensorflow as tf; print(tf.__version__)'

If there are multiple instances of Python on the system, use:

python<version> -c 'import tensorflow as tf; print(tf.__version__)'

For example:

python3 -c tensorflow version terminal output

Check TensorFlow Version in Windows Command Line

Show the TensorFlow version in the command line by running:

python -c "import tensorflow as tf; print(tf.__version__)"
python -c tensorflow version command line output

Check with a specific version of Python by adding the version number to the python command:

python<version> -c "import tensorflow as tf; print(tf.__version__)"

Check TensorFlow Version in Pip

The most common way to install Python libraries is using the pip package manager. There are two ways to print the version with pip.

Method 1: Using pip show

The pip show command prints information for any installed package.

To show the TensorFlow data, run this command:

pip show tensorflow
pip show tensorflow version output

Method 2: Using pip list

The pip list command shows all the packages installed using pip install. In Linux, use the grep command to filter out the results:

pip list | grep tensorflow
pip list grep tensorflow version output


For Windows, use findstr to filter the pip list results:

pip list | findstr "tensorflow"
pip list findstr tensorflow version output

Check TensorFlow Version in Virtual Environment

The TensorFlow documentation recommends installing the platform through a virtual environment. Activate the virtual environment before checking the version.

Step 1: Activate Virtual Environment

To activate the virtual environment, use the appropriate command for your OS:

For Linux, run:

virtualenv <environment name>

For Windows, use:

<environment name>\Scripts\activate

The environment shows up in the CLI as active:

activate virtual environment output

Step 2: Check Version

Check the version inside the environment using the python -c or pip show command.

For example:

pip show tensorflow
pip show tensorflow in virtual environment output

Check TensorFlow Version in Anaconda

Anaconda uses the conda package manager for installation. conda list shows all the libraries installed using conda install.

For Linux, filter the results with the grep command:

conda list | grep tensorflow

For Windows, combine the conda list and findstr commands to print the TensorFlow version:

conda list | findstr "tensorflow"
conda list findstr tensorflow version output

Note: The conda package manager comes with all Anaconda and Miniconda versions. To install Anaconda, follow our guides: How to Install Anaconda on CentOS7, How to Install Anaconda on CentOS8, How to Install Anaconda on Ubuntu.

Check TensorFlow Version in Jupyter Notebook

The Jupyter Notebook runs commands and Python code directly in the environment. There are two ways to check the TensorFlow version in Jupyter Notebooks.

Method 1: Using Import

Import the TensorFlow library and print the version by running the following code:

import tensorflow as tf
print(tf.__version__)
jupyter printing tensorflow version output

Method 2: Using Pip

Show the TensorFlow version using the pip command with an exclamation point:

!pip show tensorflow
jupyter !pip show tensorflow version output

Note: Learn how to upgrade or downgrade TensorFlow.

Conclusion

This tutorial explains how to check the TensorFlow version for different cases in different environments. For additional TensorFlow material, check out our comparison of PyTorch vs TensorFlow.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
Next you should read
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...
Read more
How to Install NumPy
May 8, 2024

NumPy (Numerical Python) is an open-source library for the Python programming language. It is used for...
Read more
How to Install TensorFlow GPU on Ubuntu 18.04
August 29, 2024

Designed to simplify the process of implementing machine-learning models, TensorFlow is Google's open-source...
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...
Read more