"Running cells requires Jupyter notebooks to be installed" error in VS Code

Viewed 6653

I'm trying to use the new Jupyter integration for the Python extension in VS Code, and I'm getting the above error even though I have Jupyter installed and it works fine from the command prompt.

Here's my environment:

  • Python extension version 2018.10.1, and I see Run Cell/Run All Cells tooltips above #%% comments.
  • I've used the Python: Select Interpreter command to select my Anaconda environment, which is at ~/AppData/Local/Continuum/anaconda3/python.exe.
  • I have Jupyter installed in that interpreter (jupyter.exe is in the Scripts sub-folder under that location), and it runs fine with the jupyter notebook command at the Anaconda prompt.

But whenever I click on Run Cell or press shift-enter, I get this error message: "Running cells requires Jupyter notebooks to be installed." Source: Python (Extension)

Is there something else I need to do to configure this?

3 Answers

You may give one try by restarting VS Code in following mentioned way [ It worked for me. ]

  1. Open Bash or any other cmd
  2. Activate any conda environment [ See below command ]
    • source activate base [ means activate base environment ]
  3. Run VS Code instance [ See below command ]
    • code .
  4. Now when you'll click on Run Cell or press shift-enter, it should work.

The problem is an issue in the VS Code python extension itself. There are a number of issues related to this open in the repository: #3354, #3343, #3330, and the issues are being worked on, see #3374.

The reason, as far as I understand, is that in this case - and in some other cases - the anaconda environment is not activated before running the command. Situations where the environment is activated are e.g. opening a python terminal or running a file in the python terminal, but this also needs to happen for Jupyter, Tests, and so on.

While theoretically, adding the Scripts folder to your PATH, as David mentioned, could help, it did not help in my case. This may just not be enough to properly reflect what happens on activation.

My guess is that we will have to wait for this issue to be resolved in the repo, but if someone else finds a workaround, I'd be happy.

Simply running vscode from the activated environment did not work for me, here is what did:

In terminal (bash) I ran:

conda activate <environment-name>
conda install jupyter notebook

When the install finishes, open vscode from terminal (the same shell with activated environment) with the command:

code .

Notes:

  • Replace '.' with the path to the directory you want to open if it's not the current directory.
  • I've written 'conda install ...' but mamba also works.
  • If the terminal command for 'code ' does not work, it's likely you need to add it to environemnt variables; in such a case, this post might help.
Related