7

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?

Doug Mahugh
  • 624
  • 6
  • 15
  • I'm seeing the exact same thing (except I'm not using Anaconda) – David Waterworth Nov 12 '18 at 09:00
  • I've had a similar problem. For me it worked with jupyter, when I enabled the base environment of my anaconda installation. – alybel Nov 12 '18 at 10:45
  • Check that jupyter.exe is on your path - see my answer to a similar question here - https://stackoverflow.com/questions/52287117/jupyter-is-not-recognized-as-an-internal-or-external-command/53259151#53259151 – David Waterworth Nov 12 '18 at 21:45
  • I have the same problem, and I am using the base environment. Although I can run `jupyter notebook` even from inside VS Code in a Python terminal. So it should be working. And adding it to the path completely defeats the purpose of environments, although I haven't tested whether that works. But it states on Microsofts pages that jupyter only needs to be installed in the environment, nothing about Path and whatever. I don't have python in my path and that works as well, obviously. – clocktown Nov 16 '18 at 14:28

4 Answers4

4

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.
mistertandon
  • 1,424
  • 14
  • 15
3

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.

clocktown
  • 371
  • 1
  • 3
  • 10
  • Thanks, that makes sense. My configuration is the same as yours, and I agree that it feels wrong to start messing around with the path to address this. I have no doubt I could cobble together something that would work that way, but I'd rather keep my isolation of environments clean and wait for a fix. – Doug Mahugh Nov 17 '18 at 18:43
0

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.
yosef
  • 124
  • 5
0

Although issue #3374 has been closed, the problem is still occurring in VS Code 1.76, if the Jupyter kernel is chosen from the upper right corner of the notebook. The solution is to run "Python: Select interpreter to start Jupyter server" in the Command Palette (Shift+Ctrl+P in the default VS Code setup). These instructions can be found in the Jupyter installation documentation for VS Code.

Lazer
  • 501
  • 4
  • 14