HOWTO · TensorFlow

How to Print TensorFlow Version

Check the TensorFlow package version with a shell command or from Python, and make sure you inspect the environment used by your project.

On this page

To check the TensorFlow version, query the Python environment your project uses. In a shell, pip show tensorflow reports package metadata; in Python, print tf.__version__ after importing TensorFlow. These checks report the package available in the selected environment, which may differ from another terminal, notebook kernel, or virtual environment. Checking a version does not require uninstalling TensorFlow.

Check TensorFlow Version from the Command Line

Run pip show tensorflow in the terminal associated with the environment you want to inspect. In the command output, find the Version field. This reports package metadata for the pip installation visible to that command; it does not prove that a separate Python process or notebook imports the same installation.

If you use a virtual environment, activate it before running the command. You can also invoke the environment’s own pip executable, such as python -m pip show tensorflow, so the package manager is tied to that Python interpreter. On systems with multiple Python installations, this distinction helps avoid reading metadata from a different environment than the one running your project.

Check TensorFlow Version with pip or Conda

Package listing commands are useful when you want to find TensorFlow among other installed packages. Run pip list and locate the tensorflow row; its version appears in the version column. If the environment is managed by Conda, conda list tensorflow narrows the listing to the TensorFlow package. Use the command for the environment manager and environment that your application actually uses.

These commands inspect package records, so their result can differ from an import performed by a different interpreter. If TensorFlow is absent from the listing, check that the environment is active and that the command is using its package manager. A notebook can use a different kernel from the shell, so compare from the notebook when that is where the application runs.

Check TensorFlow Version in Python with tf.__version__

The most direct Python check reads the __version__ module attribute exposed by the imported package. It is an attribute, not a dunder or magic method. Run this in the same interpreter or notebook kernel as your project:

Run this example:

import importlib.util

if importlib.util.find_spec("tensorflow") is None:
    print("TensorFlow is not installed in this Python environment.")
else:
    import tensorflow as tf
    print(tf.__version__)

The printed value is the version associated with the TensorFlow module that this Python process imported. TensorFlow must be installed in that interpreter for the import to work. If the import fails, first confirm which Python executable or notebook kernel is active, then check that environment’s package listing; a version found by a different pip command may belong elsewhere.

Check TensorFlow Version with tf.version.VERSION

TensorFlow also exposes the version string through tf.version.VERSION. This is another attribute-based check. Import the package as tf, then evaluate the expression:

import importlib.util

if importlib.util.find_spec("tensorflow") is None:
    print("TensorFlow is not installed in this Python environment.")
else:
    import tensorflow as tf
    print(tf.version.VERSION)

This value describes the imported TensorFlow package in the current Python process, just as tf.__version__ does. The two expressions are useful alternatives when inspecting code or an interactive session. For shell-based checks, package metadata is convenient; when diagnosing which version an application will use, prefer an import from that application’s actual interpreter or kernel.