unable to run jupyter notebook in vscode even when ipykernel is installed and still it shows it is not

Viewed 1902

I have used vscode for jupyter notebook for a long time, but suddenly when one day I open any notebook it gives an error

Python 3.9.2 64-bit requires ipykernel to be installed.".

I have it installed as I have been using notebook frequently and when I install it using pip, it says that it is already installed. I tried by reinstalling all the plugins of vscode, downgrading the jupyter plugin, forxe reinstalling the the ipykernel plugin except reinstalling python as .py file are working fine. I tried all the methods and restarted my computer too but it still didn't work.

I have attached an image showing that I tried to install it and then on running it didn't run.

image showing that I tried to install it and then on running it didn't run .

3 Answers

The reason is that the python environment currently used by Jupyter is different from the python environment currently used by the VS Code terminal.

  1. Please use the command "python --version" or "pip --version" to check the python currently used by the VS Code terminal:

    enter image description here

  2. Then install "ipykernel". (pip install ipykernel)

  3. In the upper right corner of Jupyter, select the python environment used by the terminal.

In addition, it is recommended that you make sure that the lower left corner of VS Code, the VS Code terminal, and Jupyter use the same python environment.

enter image description here

More references: Jupyter in VS Code and Python environments in VS Code.

I solved this by running VS Code as Administrator and reinstalling ipykernel through VS Code again.

Running

sudo apt-get install python3-ipykernel

worked for me.

Related