Richie Thomas
Richie Thomas

Reputation: 3265

VS Code- "Run" button not appearing for my Jupyter Notebook, even after installing extensions and setting kernel

TL;DR: how can I run my Jupyter notbook in VS Code, given I've tried the previously-suggested solutions (like installing certain extensions) and nothing appears to be working?


I've got the following blank .ipynb file:

'Hello world' Jupyter notebook

I've installed both Microsoft's Jupyter and Python extensions installed:

relevant installed extensions

I created the file in screenshot #1 above via the command palette to Jupyter > Create New Blank Notebook. We see a cell which I've changed from plain text to Python. I don't see a "Run" button in my editor like I do in the VS Code + Jupyter docs. I hit Shift-Enter to run the cell, but instead of the expected output, I'm prompted to "Select a kernel for Untitled-1.ipynb`:

prompt to select a kernel

I try to type in my best guess for which kernel they're referring to (I use Python 3.9.5 in my terminal), but typing things like 3.9.5 and Python, thinking I might see an auto-complete helper or a dropdown with valid options to choose from, but this didn't happen.

The "Restart" and "Interrupt" buttons are greyed-out and disabled, implying that the Jupyter server isn't running. However, the docs imply that I should be able to just create a new Jupyter notebook and start running code immediately:

Here’s how to get started with Jupyter in VS Code.

  • If you don’t already have an existing Jupyter Notebook file, open the VS Code Command Palette with the shortcut CTRL + SHIFT + P (Windows) or Command + SHIFT + P (macOS), and run the “Python: Create Blank New Jupyter Notebook” command.
  • If you already have a Jupyter Notebook file, it’s as simple as just opening that file in VS Code. It will automatically open with the new native Jupyter editor.

Once you have a Jupyter Notebook open, you can add new cells, write code in cells, run cells, and perform other notebook actions.

I saw the following Jupyter Server: local component at the bottom of my screen. I see the icon on the left-hand side shows a disconnected power cord; not sure if that implies the server itself is disconnected. At any rate, I tried clicking on this component to see what would happen:

enter image description here

I see the default behavior is already selected, which leads me to believe that VS Code would automatically start up a Jupyter server when the app itself is launched.

enter image description here

I also tried setting the kernel via the command palette (Jupyter > Select interpreter to start Jupyter server), and this time I did see my version of Python. However, selecting that option didn't seem to resolve the issue, since I still don't see a "Run" button:

selecting Python interpreter via command palette

I tried looking in all the tabs at the bottom of the screen (Terminal, Jupyter Variables, Debug Console, Problems, and Output), but didn't see anything at all.

Interestingly, when I run Jupyter > Create Interactive Window from the command palette, I am able to create Jupyter cells and run Python code in them. However, I consider this to be a workaround and not a solution to my primary problem of being unable to run both interactive sessions and notebooks:

enter image description here

These are all my VS Code settings:

{
    "ruby.intellisense": "rubyLocate",
    "files.autoSave": "onFocusChange",
    "workbench.editor.showTabs": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "files.trimTrailingWhitespace": true,
    "editor.tabSize": 2,
    "editor.tabCompletion": "on",
    "workbench.colorCustomizations": {
    "editorUnnecessaryCode.border": "#dd7aab"
    },
    "window.zoomLevel": 1,
    "terminal.integrated.shell.osx": "/bin/zsh",
    "[yaml]": {
    "breadcrumbs.showEvents": true,
        "editor.insertSpaces": true,
        "editor.tabSize": 2,
        "editor.autoIndent": "advanced"
    },
    "[html]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "workbench.editor.untitled.hint": "hidden",
    "workbench.editorAssociations": {
        "*.ipynb": "jupyter-notebook"
    },
    "notebook.cellToolbarLocation": {
        "default": "right",
        "jupyter-notebook": "left"
    },
    "python.defaultInterpreterPath": "/usr/local/bin/python3",
    "notebook.lineNumbers": "on",
    "jupyter.variableQueries": [
    
    ],
}

What am I missing?

Upvotes: 13

Views: 14708

Answers (4)

ratehotchilipeppers
ratehotchilipeppers

Reputation: 21

  1. Go to Extension
  2. Search "Jupyter" from Microsoft
  3. Click "Switch to Pre-Release Version"
  4. Click "Reload"

VS Code Extension

Upvotes: 2

masanmola
masanmola

Reputation: 111

I had this issue too and solved it by:

pip install ipython

After installing this package and Jupyter extensions in Visual Studio code, the run button is available left of the cell and you can click it to run the cell.

Then it tries to connect to the kernel and for the first time asks you to install Ipykernel if it doesn't show this message, etc you can run this code in Command Prompt:

python -m pip install ipykernel

also for more information, you can see this page:
https://ipython.readthedocs.io/en/latest/install/index.html

Upvotes: 0

Blue Snow
Blue Snow

Reputation: 53

I am not sure if you're still searching for an answer. What worked for me was to install conda (anaconda or miniconda will do). Then in the command prompt, type:

conda install ipykernel 

Restart your IDE and it should work!

Upvotes: 1

Atharv kumar
Atharv kumar

Reputation: 25

Here is your answer,

1.Just refresh your IDE and then restart your IDE . 2.INSTALL KERNEL ON YOUR IDE.

Sometimes extensions in IDE must not have hosted therefore the extensions does not work.In this case just restart your IDE and then host your extensions.

Upvotes: 1

Related Questions