Note: you may need to restart the kernel to use updated packages

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# Note: you may need to restart the kernel to use updated packages

To resolve the Jupyter issue "Note: you may need to restart the kernel to use updated packages":

  1. Restart your kernel and try refreshing the browser.
  2. Try running the pip install command with the --upgrade option.
  3. Create a new virtual environment and switch to it in Jupyter Notebook.

# Restarting the kernel

The first thing you should try is to restart the kernel.

To restart the kernel:

  1. Click on Kernel in the top menu.
  2. Click on Restart and confirm by clicking on the Restart button again.

jupyter restart kernel

  1. To restore your variables rerun your code by pressing CTRL + Enter or clicking on the > Run button.

If the message is still shown when installing packages, try to refresh the page in your browser by pressing F5.

# Use the --upgrade flag when installing

If the message is still shown, try to issue the pip install command with the --upgrade option.

shell
!pip install numpy --upgrade

Make sure to replace numpy with the name of the package you're trying to install.

# Creating a new virtual environment

If the message is still shown, try to create a new virtual environment.

To create a new virtual environment:

  1. Open your terminal and run the following commands to create and activate a virtual environment.
shell
# ๐Ÿ‘‡๏ธ Use the correct version of Python when creating VENV python -m venv venv # ๐Ÿ‘‡๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1

If the python -m venv venv command doesn't work, try the following 2 commands:

  • py -m venv venv
  • python3 -m venv venv

Make sure to use the correct command to activate your virtual environment depending on your operating system and your shell.

create activate virtual environment

  1. Issue the following commands from your terminal with the virtual environment active.
shell
pip install ipykernel ipython kernel install --user --name=venv

pip install ipykernel

  1. Restart the Kernel by clicking on Kernel > Restart and refresh the page in your browser by pressing F5.

jupyter restart kernel

  1. Alternatively, you can issue the jupyter notebook command from your terminal.
shell
jupyter notebook
  1. Once you refresh the page, click on Kernel in the top bar and hover over the Change kernel menu.

jupyter change kernel

  1. Select venv from the Change kernel menu and install all your packages.

  2. Make sure the venv kernel is selected and shown in the top right corner.

venv-kernel-selected

  1. Install all your packages in the new virtual environment.

If you still get the message when running pip install <package>, try to upgrade pip by running the following command from your terminal.

shell
# ๐Ÿ‘‡๏ธ On Linux or macOS python -m ensurepip --upgrade # ๐Ÿ‘‡๏ธ Using python 3 python3 -m ensurepip --upgrade # ๐Ÿ‘‡๏ธ On Windows py -m ensurepip --upgrade
The ensurepip package enables us to bootstrap the pip installer into an existing Python installation or virtual environment.

# Using the get-pip.py script to upgrade pip

Alternatively, you can use the official get-pip script to install pip.

Download the script from https://bootstrap.pypa.io/get-pip.py by:

  1. Clicking on the link.
  2. Right-clicking and selecting "Save as" in your browser.
Open your terminal in the location where the get-pip.py file is downloaded and run the following command.
shell
# ๐Ÿ‘‡๏ธ On Linux or macOS python get-pip.py # ๐Ÿ‘‡๏ธ Using python 3 python3 get-pip.py # ๐Ÿ‘‡๏ธ On Windows py get-pip.py

The get-pip.py script uses bootstrapping logic to install pip.

You can also download the script using curl (if you have curl installed).
shell
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # ๐Ÿ‘‡๏ธ On Linux or macOS python get-pip.py --force-reinstall # ๐Ÿ‘‡๏ธ Using python 3 python3 get-pip.py --force-reinstall # ๐Ÿ‘‡๏ธ On Windows py get-pip.py --force-reinstall

The --force-reinstall option forces pip to reinstall the package.

If you still get the error, click on Kernel in the top menu and click Shutdown.

kernel shutdown

Then refresh the page, click on Kernel in the top bar and hover over the Change kernel menu.

jupyter change kernel

Select venv from the Change kernel menu and install all your packages.

# 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.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev