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 several ways to check the version of TensorFlow depending on the installation method.
This article shows you how to check your TensorFlow version in six different ways.
prerequisites
Installed Python 2 or Python
- 3 Installed
- installed (Try our guides: How to install TensorFlow on CentOS, How to install TensorFlow GPU on Ubuntu).
- CLI
TensorFlow
or IDE Access
Check
the version of TensorFlow in Python
The easiest way to check the version of TensorFlow 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
Latest versions
TensorFlow
2.x releases 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)
Previous versions
of TensorFlow TensorFlow 1.x has a slightly different method for checking the library version. Print the version for previous builds of TensorFlow in Python by running:
import tensorflow as tf print(tf. VERSION) Check the TensorFlow version in the CLI Show 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
the version of TensorFlow in the Linux terminal
Print the version of TensorFlow 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
: Check the version of TensorFlow on the Windows command line Display the
version of TensorFlow on
the command line by running:
python -c “import tensorflow as tf; print(tf.__version__)”
Check with a specific Python version 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 to use the pip package manager. There are two ways to print the pip version.
Method 1: Using pip show The pip show command
prints information for any installed packages
.
To display TensorFlow data, run this command
: pip show tensorflow
Method 2: Using
pip list The pip list
command displays all packages installed using pip install. On Linux, use the grep command to filter the results:
pip list | grep tensorflow
For Windows, use findstr to filter pip list results: pip list
| findstr “tensorflow” Check the version of TensorFlow
in
the virtual environment
The TensorFlow documentation recommends installing the platform through a virtual environment. Activate the virtual environment before checking the version.
Step
1: Activate
the virtual environment To activate the virtual environment, use the appropriate command
for your operating system
: For Linux,
run
: virtualenv <environment name> For
Windows, use
: <environment name>\Scripts\activate The environment
appears in the CLI as active
:
Step 2
: Check Version
Check the version within the environment using the python -c or pip show command.
For example:
pip show tensorflow
Check the version of TensorFlow in Anaconda Anaconda
uses the conda package manager for installation. The CONDA list shows all libraries installed using conda install.
For Linux, filter the results with the command grep:
conda list | grep tensorflow
For Windows, combine the conda list and findstr commands to print the version of TensorFlow: conda list
| findstr “tensorflow”
Check the version of TensorFlow
in Jupyter Notebook
Jupyter Notebook executes commands and Python code directly in the environment. There are two ways to check the version of TensorFlow 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__)
Method 2: Using Pip
Display the
TensorFlow version using the pip command with an exclamation point: ! pip
show tensorflow
Conclusion
This tutorial explains how to check
the version of TensorFlow
for different cases in different environments. For additional TensorFlow material, check out our PyTorch vs TensorFlow comparison.