- Changing the Python version Jupyter uses
- Double-checking the kernel installed correctly
- Installing the classic Jupyter Notebook interface#
- Prerequisite: Python#
- Installing Jupyter using Anaconda and conda#
- Alternative for experienced Python users: Installing Jupyter with pip#
- Jupyter notebook python version
- # How to check your Python version in Jupyter Notebook
- # Check your Python interpreter in Jupyter Notebook using the sys module
- # Using the !python —version command to check your version
- # Using the menu to check your Python version in Jupyter Notebook
- # Additional Resources
- How to Check Python Version in Jupyter Notebook?
- Check Version Information Using sys Module
- Check Version Using Exclamation Mark
- Check Jupyter Notebook Python Version on Your Computer
- Programming Humor – Python
Changing the Python version Jupyter uses
Sometimes you want to change the version of Python that Jupyter is using! Often this is because you want to make your command-line python command match the version that Jupyter is using.
Jupyter doesn’t use the PATH variable to figure out which Python to use, it uses specific settings called kernels. As a result, if you upgrade or change Pythons on the command line, Jupyter might still be stuck in the past!
You can read more about how this causes libraries to go missing, but we’re just going to jump into changing it here. Our process is only three quick steps:
- Confirm our Python version
- Install the ipykernel package for managing Jupyter settings
- Use ipykernel to change our default Jupyter
$ python --version Python 3.10.0 $ python -m pip install ipykernel $ python -m ipykernel install --user Installed kernelspec python3 in /Users/soma/Library/Jupyter/kernels/python3
This kernel or kernelspec is the settings file that Jupyter uses to figure out what Python it should point to. Now it’s updated, so everything should work great! Shut down your Jupyter notebook server, start a new one, and you’ll be good to go.
When I say “shut down your Jupyter notebook server,” I don’t mean close your notebook tab: that isn’t enough! You need to actually turn off and restart the entire Jupyter server. Use Ctrl+C to shut it down from the command line.
Double-checking the kernel installed correctly
If we’re nosy or suspicious, we could actually look at the kernel’s details. Read the last line of the output to see where the kernelspec (kernel specification) lives:
$ python -m ipykernel install --user Installed kernelspec python3 in /Users/soma/Library/Jupyter/kernels/python3
The settings are stored in a file called kernel.json inside of this folder. To check up on the details, we can use the cat command.
$ cat /Users/soma/Library/Jupyter/kernels/python3/kernel.json "argv": [ "/Users/soma/.pyenv/versions/3.10.0/bin/python", "-m", "ipykernel_launcher", "-f", "" ], "display_name": "Python 3 (ipykernel)", "language": "python", "metadata": "debugger": true > >
The important part here is /Users/soma/.pyenv/versions/3.10.0/bin/python — that’s the exact Python file that Jupyter will be running!
Installing the classic Jupyter Notebook interface#
This section includes instructions on how to get started with Jupyter Notebook. But there are multiple Jupyter user interfaces one can use, based on their needs. Please checkout the list and links below for additional information and instructions about how to get started with each of them.
This information explains how to install the Jupyter Notebook and the IPython kernel.
Prerequisite: Python#
While Jupyter runs code in many programming languages, Python is a requirement for installing the Jupyter Notebook. The Python version required differs between Jupyter Notebook releases (e.g. Python 3.6+ for Notebook v6.3, and Python 3.7+ for Notebook v7) .
We recommend using the Anaconda distribution to install Python and Jupyter. We’ll go through its installation in the next section.
Installing Jupyter using Anaconda and conda#
For new users, we highly recommend installing Anaconda. Anaconda conveniently installs Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science.
Use the following installation steps:
- Download Anaconda. We recommend downloading Anaconda’s latest Python 3 version (currently Python 3.9).
- Install the version of Anaconda which you downloaded, following the instructions on the download page.
- Congratulations, you have installed Jupyter Notebook. To run the notebook:
Alternative for experienced Python users: Installing Jupyter with pip#
Jupyter installation requires Python 3.3 or greater, or Python 2.7. IPython 1.x, which included the parts that later became Jupyter, was the last version to support Python 3.2 and 2.6.
As an existing Python user, you may wish to install Jupyter using Python’s package manager, pip , instead of Anaconda.
First, ensure that you have the latest pip; older versions may have trouble with some dependencies:
Then install the Jupyter Notebook using:
(Use pip if using legacy Python 2.)
Congratulations. You have installed Jupyter Notebook. See Running the Notebook for more details.
Upgrading Jupyter Notebook
Jupyter notebook python version
Last updated: Apr 13, 2023
Reading time · 3 min
# How to check your Python version in Jupyter Notebook
The easiest way to check your Python version in Jupyter Notebook is to:
- Import the python_version method from the platform module.
- Call the python_version() method to print the Python version as a string.
Start Jupyter Notebook by issuing the jupyter-notebook command from your terminal.
Click on New and select Python 3 (ipykernel).
Now, import the python_version method from the platform module and call it.
Copied!from platform import python_version print(python_version())
Once you import and call the method, click on the Run button or press Ctrl + Enter .
The screenshot shows that my Python version is 3.11.3.
The code sample imports the python_version method from the platform module.
Unlike the sys.version attribute, the string always contains the patch component (even if it’s 0 ).
If you have virtual environments that you are trying to switch to from within Jupyter Notebook:
- Click on Kernel.
- Hover over Change kernel.
- Select your virtual environment.
If you encounter any issues when switching virtual environments, restart the kernel.
If you need to create a new virtual environment in Jupyter Notebook, follow the instructions in this article.
# Check your Python interpreter in Jupyter Notebook using the sys module
You can use the sys module if you need to check your Python interpreter in Jupyter Notebook.
Copied!import sys print(sys.executable) # 👉️ /usr/bin/python3.11
The sys.executable attribute returns the absolute path of the executable binary of the Python interpreter.
If Python can’t determine the path to the interpreter, then sys.executable returns an empty string or a None value.
There is also a sys.version attribute that returns a string containing:
- the version number of the Python interpreter
- additional information about the build number and the compiler
Copied!import sys print(sys.executable) # /usr/bin/python3.11 # 👇️ 3.11.3 (main, Apr 5 2023, 14:14:37) [GCC 11.3.0] print(sys.version) # 👇️ sys.version_info(major=3, minor=11, # micro=3, releaselevel='final', serial=0) print(sys.version_info)
The sys.version_info attribute returns a tuple that contains five components of the version number:
All components except for the release level are integers.
The release level component can be one of the following:
You can access specific tuple elements at an index.
Copied!import sys # 👇️ sys.version_info(major=3, minor=11, # micro=3, releaselevel='final', serial=0) print(sys.version_info) print(sys.version_info[0]) # 3 print(sys.version_info[1]) # 11 print(sys.version_info[2]) # 3 print(sys.version_info[3]) # final
# Using the !python —version command to check your version
You can also use the !python —version command to check your Python version in Jupyter Notebook.
Copied!!python --version # same as above !python -V
The !python -V command is an alias of the !python —version command.
Notice that the command is prefixed with an exclamation mark.
This is necessary when issuing the command in a Jupyter cell.
The exclamation mark ! is used to run a shell command in Jupyter.
You can use the !jupyter —version command if you need to check your Jupyter version.
# Using the menu to check your Python version in Jupyter Notebook
You can also use the Help menu to check your Python version in Jupyter Notebook:
- The version of the notebook server
- The Python version that is run in Jupyter Notebook
- Additional information about the current kernel
If you encounter issues when checking your version, try restarting the kernel.
# Additional Resources
You can learn more about the related topics by checking out the following tutorials:
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
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: