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 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:
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 notebook in 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 that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a 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.
Be on the Right Side of Change 🚀
- The world is changing exponentially. Disruptive technologies such as AI, crypto, and automation eliminate entire industries. 🤖
- Do you feel uncertain and afraid of being replaced by machines, leaving you without money, purpose, or value? Fear not! There a way to not merely survive but thrive in this new world!
- Finxter is here to help you stay ahead of the curve, so you can keep winning as paradigms shift.
Learning Resources 🧑💻
⭐ Boost your skills. Join our free email academy with daily emails teaching exponential with 1000+ tutorials on AI, data science, Python, freelancing, and Blockchain development!
Join the Finxter Academy and unlock access to premium courses 👑 to certify your skills in exponential technologies and programming.
New Finxter Tutorials:
Finxter Categories: