17

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
  • 499
  • 2
  • 8
  • 17
johnwow
  • 267
  • 1
  • 2
  • 10
  • 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

9 Answers9

15

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
  • 7,195
  • 1
  • 13
  • 22
  • 7
    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
  • 2
    @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
7

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
  • 71
  • 1
  • 1
6

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
  • 1,976
  • 2
  • 13
  • 21
3

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
  • 5,738
  • 1
  • 3
  • 11
2

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
1

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
  • 55,661
  • 11
  • 60
  • 99
Kelvin
  • 21
  • 2
0

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
  • 24,927
  • 44
  • 149
  • 234
0

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

pcko1
  • 559
  • 9
  • 15
0

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
  • 178
  • 1
  • 11