How to Print TensorFlow Version

Anika Tabassum Era Feb 15, 2024
  1. Check TensorFlow Version via the Command Prompt
  2. Check TensorFlow Version With pip List
  3. Use Dunder Method to Check TensorFlow Version
  4. Use Attribute to Check TensorFlow Version
How to Print TensorFlow Version

TensorFlow is a substantial machine learning library and often gets updated with newer modifications and possibilities.

It is a good practice to uninstall the packages after every use, as they are constantly upgrading. In this regard, we should also be aware of the package version we are dealing with.

There are multiple ways to check the version of TensorFlow. One of the basic drives is to instantiate the command prompt.

Next, we have the pip list that incorporates all the installed packages with names and versions. We can count on that pip list.

The other processes to check the version of TensorFlow includes two popular attributes. One is termed the magic method, the .__version__, and the other is .version.VERSION.

In the following section, we will see the preview of all the systems to check the version of the TensorFlow package installed.

Check TensorFlow Version via the Command Prompt

We have followed the Anaconda navigator and its application CMD.exe Prompt to initiate the terminal. After opening a new window of the terminal, the line is to be typed.

pip show tensorflow

After pressing Enter, the output will show as follows, and you will be able to retrieve the version of the installed TensorFlow.

Output:

Check tensorflow version via the command prompt

Check TensorFlow Version With pip List

This drive is basic as the pip list, or conda list interchangeably presents all the installed packages with the name and corresponding version. So, when the following line is run in the code cell, the output can define the installed TensorFlow and its version.

Let’s check the code and preview.

!pip list
# or
!conda list

Output:

Check tensorflow version with pip list

Use Dunder Method to Check TensorFlow Version

One dunder method is available in Python to check the version of TensorFlow or any other package that is .__version__. This is often entitled as the magic method.

All it requires is to import the package and then use the variable (through which the package was imported) with the attribute. Let’s check the following code lines and output.

import tensorflow as tf

print(tf.__version__)

Output:

Use Dunder method to check tensorflow version

Use Attribute to Check TensorFlow Version

In this regard, we will rely on the attribute .version.VERSION. The previous form of this method was just a simple .version, but it is deprecated.

So, we will import the TensorFlow, and along with the variable imported, we will run the following for the expected output.

import tensorflow as tf

print(tf.version.VERSION)

Output:

Use attributes to check version of tensorflow

Anika Tabassum Era avatar Anika Tabassum Era avatar

Era is an observer who loves cracking the ambiguos barriers. An AI enthusiast to help others with the drive and develop a stronger community.

LinkedIn Facebook