36

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.

Wouter
  • 534
  • 3
  • 14
  • 22
johnwow
  • 477
  • 1
  • 6
  • 12
  • Can you look into [this](https://stackoverflow.com/questions/67818911/failed-to-change-the-jupyter-kernel-in-vs-code/67833255#67833255) answer? Maybe it can provide some help. – Steven-MSFT Jun 08 '21 at 02:48
  • 1
    The issue may also be caused by: [Jupyter notebooks in Visual Studio Code does not use the active virtual environment](https://stackoverflow.com/questions/58119823/jupyter-notebooks-in-visual-studio-code-does-not-use-the-active-virtual-environm). – bluenote10 Jun 13 '22 at 14:46

21 Answers21

25

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.

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
  • 15
    This "solution" 100% does not solve the problem. Countless hours spent trying to solve this `ipykernel` issue despite confirming multiple times that it is indeed installed within the Conda virtual environment. Time to pivot to another IDE; this is ridiculous. – JohnnyUtah Apr 19 '21 at 15:59
  • How to check for the environment being used on VSCode? The interpreter options for me are only Python 3.7.x and Python 2.7.x. – BharathYes Jun 06 '21 at 15:55
  • [This link](https://stackoverflow.com/questions/67818911/failed-to-change-the-jupyter-kernel-in-vs-code/67833255#67833255) may be helpful. – Steven-MSFT Jun 08 '21 at 02:50
  • @JohnnyUtah Can you check [this link](https://stackoverflow.com/questions/67818911/failed-to-change-the-jupyter-kernel-in-vs-code/67833255#67833255)? – Steven-MSFT Jun 08 '21 at 02:52
  • 4
    @JohnnyUtah, had the same problem. Ctrl+Shift+P ">Jupyter: Select Interpreter to start Jupyter server" led me to realize my environment was missing "notebook" package, not ipykernel. – Jacob Church Sep 29 '21 at 00:56
  • 1
    `conda install -c conda-forge notebook` should solve the issue – Semuserable Oct 01 '21 at 18:26
19

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.

Marcus
  • 2,153
  • 2
  • 13
  • 21
Neelabh Somani
  • 214
  • 2
  • 3
12

Just Do A : pip install ipykernel --upgrade

  • 1
    It's an environment problem, see accepted answer. It's ok to manually install ipykernel using pip but you must be sure to select the correct environment. Please update your answer. – nico9T Apr 09 '21 at 08:28
  • This worked for me, anyway. – Biodun Solanke Aug 01 '22 at 19:34
  • @nico9T In my case, I have already done the same as the accepted answer. I have selected the correct environment, and ipykernel is also installed but it still does not work. It isn't very clear btw, but this simple reinstalling with --upgrade works finally. – Aung Si Min Htet Apr 13 '23 at 07:46
12

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.

Shane Wolff
  • 121
  • 1
  • 3
4

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.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
3

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

cigien
  • 57,834
  • 11
  • 73
  • 112
Kelvin
  • 51
  • 3
1

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?

bguiz
  • 27,371
  • 47
  • 154
  • 243
1

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

pcko1
  • 833
  • 12
  • 22
1

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.

Vikram
  • 332
  • 3
  • 16
1

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

Sanketsz
  • 138
  • 4
1

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

0

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.

Hadij
  • 3,661
  • 5
  • 26
  • 48
0

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

Sami
  • 41
  • 6
0

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

0

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

0

This happens to me because the version of conda is low, which leads to the low version of ipykernel installed. You need to update the conda version and then install it with the conda command or use pip install ipython ipykernel to install.

windyxh
  • 1
  • 1
0

I was using Linux (no Conda), and I had the same problem. I found out that there were some missing packages for which the Jupyter notebook was not starting.

The first thing that I checked was to see if I could launch jupyter notebook outside of VSCode by running jupyter notebook in a terminal. Running this command generated an error and showed me what packages I was missing (for example pysqlite).

Installing all the required packages and being able to run jupyter notebook outside of VSCode, also solved the problem inside VSCode.

Daniel Srp
  • 373
  • 1
  • 2
  • 9
0

use This command c:/Python311/python.exe -m pip install ipykernel -U --user --force-reinstall Vs code editor recommended command

0

To solve the problem you need:

  1. Create a virtual environment using the command: python -m venv /path/to/new/virtual/<your_environment_name>
  2. Activate this virtual environment using the command: /path/to/new/virtual/<your_environment_name>\Scripts\activate
  3. Install the ipykernel library into the virtual environment using the command: pip install -U ipykernel
  4. Define the interpreter of the created virtual environment to your file with the iponb extension using button in the upper right corner: enter image description here
imartov
  • 17
  • 4
0

Since I needed a Python env with a different (lower) version, I created one directly for a JuPyter notebook with an available IPython-Kernel as described in the documentation: https://ipython.readthedocs.io/en/stable/install/kernel_install.html

conda create -n ipykernel_py2 python=2 ipykernel
source activate ipykernel_py2    # On Windows, remove the word 'source'
python -m ipykernel install --user

-2

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