TensorFlow projects often move between notebooks, training shells, build runners, and deployment images, and each place can import a different Python package set. Reading the version from the active interpreter shows which TensorFlow release will run the code before comparing results or debugging compatibility.
Importing TensorFlow and printing tf.__version__ asks the same runtime that model code uses. The pip metadata check adds the installed package path when the version needs to be tied back to a virtual environment, Conda environment, or container image.
Run the check from the environment that will execute the model code. If Python raises ModuleNotFoundError, the selected interpreter does not have TensorFlow installed; activate the project environment or call the exact executable used by the project before trusting the output.
Steps to check the TensorFlow version:
- Check the Python interpreter version in the target environment.
$ python3 --version Python 3.12.13
Current TensorFlow 2.21 packages support CPython 3.10 through 3.13. If python3 points to a different interpreter, activate the project environment or use the exact executable from that environment.
- Print the TensorFlow version imported by that interpreter.
$ python3 -c "import tensorflow as tf; print(tf.__version__)" 2.21.0
A version line confirms that the selected interpreter can import TensorFlow. ModuleNotFoundError means that interpreter does not have the package installed.
- Read the TensorFlow package metadata from that interpreter's pip module.
$ python3 -m pip show tensorflow Name: tensorflow Version: 2.21.0 Summary: TensorFlow is an open source machine learning framework for everyone. Home-page: https://www.tensorflow.org/ ##### snipped ##### Location: /usr/local/lib/python3.12/site-packages Requires: absl-py, astunparse, flatbuffers, gast, google_pasta, grpcio, h5py, keras, libclang, ml_dtypes, numpy, opt_einsum, packaging, protobuf, requests, setuptools, six, termcolor, typing_extensions, wrapt Required-by:
Use the Version line for the installed release and the Location line to confirm which environment owns the package.
Related: How to install TensorFlow with pip - Run the import with an exact interpreter name when multiple supported Python versions are installed.
$ python3.12 -c "import tensorflow as tf; print(tf.__version__)" 2.21.0
On Windows, use the Python Launcher selector for the project version, such as py -3.12 -c "import tensorflow as tf; print(tf.__version__)".
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.