Python requires ipykernel to be installed

Question:

I encounter an issue when I use the Jupyter Notebook in VS code. The screen shows "Python 3.7.8 requires ipykernel to be installed". I followed the pop-up to install ipykernel. It still does not work. The screenshot is attached. It bothers me a lot. Could anyone help me with it? Tons of thanks.

Screenshot of VSCode displaying the error message.

Asked By: johnwow

||

Answers:

The reason is that your current VSCode terminal is in the environment "Deeplearning_Env", so "ipykernel" is installed in the environment "Deeplearning_Env" instead of the environment "base conda" displayed in the pop-up box.

Solution: Please use the shortcut key Ctrl+Shift+` to open a new VScode terminal, it will automatically enter the currently selected VSCode environment (VSCode lower left corner), and activate this conda environment:

enter image description here

Then, click to install "ipykernel" according to the prompt in the pop-up box.
Or, we could also install "ipykernel" manually: (pip install ipykernel)

In addition, for the newly created Python environment (without installing "ipykernel"), before opening the Jupyter file, please refresh the VSCode terminal and enter the currently selected environment. For the conda environment, we need to activate it before using it.

Check: Check the installation of "ipykernel":

enter image description here

More reference: Environment in VSCode.

Answered By: Jill Cheng

Change the JSON schema and point to your environment.

If you encounter problems, create a new environment.

See also: How to setup virtual environment for Python in VS Code?

Answered By: fedemoreno613

Just Do A :
pip install ipykernel –upgrade

Answered By: Parth Kshirsagar

The pyzmq package installed in the conda(base) environment caused it. You can solve the problem through uninstall and reinstall the ‘pyzmq’ package under the conda(base) environment.

pip uninstall pyzmq
pip install pyzmq

You can refer to here for more details.

Answered By: Steven-MSFT

Recently I ran into this problem and personally I believe that this problem specifically emerges if you are using a conda environment. Even if you upgrade the ipykernel in the right environment, the problem persists. Install the nb_conda_kernels package in the conda environment you want to use with your Jupyter notebook.

conda install -n notebook_env nb_conda_kernels

Replace the notebook_env in the above command with the actual environment name you use. Check out this repository for further reference.

Answered By: Shane Wolff

In my case, I had to pip install jupyter, not ipykernel as implied by the error message.

Answered By: pcko1

I had the same issue and spent the whole day trying to resolve it. What worked for me was installing the Jupyter dependencies for anaconda:

> conda install jupyter

I installed this in my base environment. After this VSCode worked without any errors.

Answered By: Neelabh Somani

Maybe you can try type this cmd in the terminal. And let see what happen.

python -m ipykernel

I got sth error after I had typed this cmd.

ImportError: cannot import name ‘AsyncGenerator’

The fix is from https://stackoverflow.com/a/65557088/11474510

pip install –upgrade prompt-toolkit==2.0.1

Answered By: Kelvin

The problem mentioned is not specific to conda based virtual environments.

My config:
Python 3.7.8,
VS Code: 1.63.2,
OS: Windows 10 64 bit,
venv for virtual environment

I am using python venv for virtual environment. When i imported a new .ipynb file in VS Code while trying to run it, it gave the error "Running cells with Python 3.7.8(env_name:venv) require ipykernel package".

I hit the pop up to install and can see the following being installed in the selected virtual environment/kernel i am using with my Jupyter notebook.

xxx/xxx/../python.exe -m pip install -U ipykernel

and finally, the installed packages:

Installing collected packages: wcwidth, traitlets, parso, tornado, pyzmq, pygments, prompt-toolkit, pickleshare, nest-asyncio, matplotlib-inline, jupyter-core, jedi, entrypoints, decorator, backcall, jupyter-client, ipython, debugpy, argcomplete, ipykernel
Successfully installed argcomplete-2.0.0 backcall-0.2.0 debugpy-1.5.1 decorator-5.1.1 entrypoints-0.3 ipykernel-6.6.1 ipython-7.31.0 jedi-0.18.1 jupyter-client-7.1.0 jupyter-core-4.9.1 matplotlib-inline-0.1.3 nest-asyncio-1.5.4 parso-0.8.3 pickleshare-0.7.5 prompt-toolkit-3.0.24 pygments-2.11.2 pyzmq-22.3.0 tornado-6.1 traitlets-5.1.1 wcwidth-0.2.5

You can start with installing ipykernel directly in the selected environment.

Answered By: Vikram

I too faced the same issue, so simply I made the new environment and changed the kernel in vscode.

Answered By: Sanketsz

try conda install -n base ipykernel --update-deps --force-reinstall

Answered By: Bayebayesian

This is how the problem is solved for me:

I ran this:

pip install --upgrade --force jupyter-console

Then I got an error for botocore conflict (You may get an error for another package). I installed botocore:

pip uninstall botocore

An then rerun the above code:

pip install --upgrade --force jupyter-console

If you received a conflict error for other packages, continue removing them and taking the same steps until there is no error. When jupyter-console successfully installs, you won’t see the Kernel error again.

Answered By: Hadij

Recently, I ran into the same problem twice after updating VS Code. When I tried to run a cell in a Jupyter notebook, it said I need to install a python extension (even though I had it installed). But I just went to the python extension and switched the version. That’s it, it worked for me like that.

Python Extension Page

Answered By: Sami

If you have a USB drive plugged in with an unrecognized file system, then VS code can’t run notebooks because the "jupyter notebook" command crashes

Answered By: Timotheeee

1.open cmd as administrator
2.Run the following. python -m pip install ipykernel -U –user –force-reinstall

Answered By: Test Up4

I just solved this by installing latest version (3.11) of python

Answered By: Haroon Sadiq