How to Check Python Version in Jupyter Notebook?

To check the Python version in your Jupyter notebook, first import the python_version function with “from platform import python_version“. Then call the function python_version() that returns a string with the version number running in your Jupyter notebook such as "3.7.11".

You can try this yourself in our interactive Jupyter notebook:

Check Version Information Using sys Module

You can use any of the following three functions to check the version information in your Jupyter notebook like sso:

import sys
print(sys.executable)
print(sys.version)
print(sys.version_info)

The output in my notebook is:

/usr/bin/python3
3.7.11 (default, Jul  3 2021, 18:01:19) 
[GCC 7.5.0]
sys.version_info(major=3, minor=7, micro=11, releaselevel='final', serial=0)

You can try this yourself in the interactive Jupyter notebook too:

You can see that this not only prints the Python version but also the compiler info, the installation path and other useful information.

Check Version Using Exclamation Mark

What many coders using Jupyter notebooks do not know is that Jupyter notebooks provide you the exclamation mark operator that allows you to execute commands on the underlying operating system.

To check the Python version, run !python -V or !python --version in your Jupyter notebook cell. This is the operating system command you’d use to check your Python version in your terminal or command line—prefixed with an exclamation mark. This only works in Jupyter notebooks but not in normal Python scripts.

Here’s how this looks like in our interactive Jupyter notebook:

And here’s for copy&paste:

!python -V

Check Jupyter Notebook Python Version on Your Computer

Perform the three steps to check the Python version in a Jupyter notebook.

  1. Open the Jupyter notebook: type jupyter notebook in your terminal/console.
  2. Write the following Python code snippet in a code cell:
from platform import python_version
print(python_version())

3. Execute the script.

Here is a screenshot on my computer:

As an alternative, you can also use the following Python code snippet to check your Python version in a Jupyter notebook:

import sys
print(sys.version)