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
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 so:
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:
Check Jupyter Notebook Python Version on Your Computer
Perform the three steps to check the Python version in a Jupyter notebook.
- Open the Jupyter notebook: type
jupyter notebookin your terminal/console.
- 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)
Programming Humor – Python
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.