VS Code: jupyter notebook run line by line - visual-studio-code

Recently VSCode got an update and after that my jupyter notebook interface has changed which created a lot of problems for me. Now I don't know how to run cell code line by line, etc.
Is there any other way to do so or how can I get back to an older version of the notebook?

Open the command palette (Ctrl+Shift+P on Windows, Cmd+Shift+P on Mac)
Type 'Preferences: Open Settings (JSON)' and select the first option to open your user settings.json file
Add the following line to your user settings.json file:
"jupyter.experiments.optOutFrom": ["NativeNotebookEditor"],
If the following entry is present in your user settings.json file, delete it:
"workbench.editorAssociations": [
{
"viewType": "jupyter-notebook",
"filenamePattern": "*.ipynb"
}
]
Reload Visual Studio Code for the new settings to take effect. You should be opted back into the old Jupyter notebook interface.

If you want to run a python script line by line using Jupyter interpreter this is the option you need to tick in VS code settings.

In v1.60 (see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_60.md#jupyter):
VS Code now supports the Run By Line feature in Jupyter notebooks.
This is a simple debug mode that lets you execute the code of a cell
line by line. To try it out, just make sure that you have ipykernel v6+ installed as your selected kernel, then select the Run By Line
button.
Previously:
In vscode 1.59 (see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_59.md#jupyter-run-by-line)
Jupyter "Run By Line"
We've been working on supporting the "Run By Line" feature in Jupyter
notebooks. This feature is essentially a simplified debug mode that
lets you step through your cell's code line by line without any
complex debug UI. This is still experimental, but you can try it out
by setting "jupyter.experimental.debugging": true, installing
version 6 of ipykernel in your selected kernel, then clicking the "Run
By Line" button in the cell toolbar.
"jupyter.experimental.debugging": true

Related

Stop automatic `conda activate` when opening a terminal in VS Code

VS Code has started running conda activate every time I open a terminal in VSCode, be it PowerShell, WSL, or CMD.
I never set this up intentionally so have no idea why it does this or how to disable it. I've looked at all my settings in VS Code and cannot find anything.
How do I stop VS Code from running conda activate when a new terminal is opened?
Try putting the following in your settings.json file:
"python.terminal.activateEnvironment": false
You're getting this behaviour because the default value of that setting is true if not specified.
For more info, see VS Code's docs on Using Python environments in VS Code- in particular, the Working with Python interpreters
section, and the Environments and Terminal windows
section.
Quoting from that page:
Tip: To prevent automatic activation of a selected environment, add "python.terminal.activateEnvironment": false to your settings.json file (it can be placed anywhere as a sibling to the existing settings).
Reading the changelog, this setting was added in version 2018.9.0 of the Python extension for VS Code. The PR that added it was #1387.

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:
I've installed both Microsoft's Jupyter and Python extensions installed:
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`:
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:
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.
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:
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:
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?
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.
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!
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
Go to Extension
Search "Jupyter" from Microsoft
Click "Switch to Pre-Release Version"
Click "Reload"
VS Code Extension

Line number of edit window not showing in interactive window using Visual Studio and conda enviroment

I created a python project with Visual Studio, expecting to develop with conda and ipython, so I set the enviroment to Conda, and made sure to check the ipython within it...
I am expecting the following result, which has references to line numbers in the interactive window:
Turns out that i am getting this (without the line number):
What am I missing to achieve the desired result?
For this walkthrough you should have the Anaconda environment installed, which includes IPython and the necessary libraries:
Open Visual Studio, switch to the Python Environments window (View >
Other Windows > Python Environments), and select an Anaconda
environment.
Examine the Packages (Conda) tab (which may appear as pip or
Packages) for that environment to make sure that ipython and
matplotlib are listed. If not, install them here. (See Python
Environments windows - Packages tab.)
Select the Overview tab and select Use IPython interactive mode. (In
Visual Studio 2015, select Configure interactive options to open the
Options dialog, then set Interactive Mode to IPython, and select
OK).
Select Open interactive window to bring up the Interactive window in
IPython mode. You may need to reset the window if you have just
changed the interactive mode; you might also need to press Enter if
only a >>> prompt appears, so that you get a prompt like In [2].
https://learn.microsoft.com/en-us/visualstudio/python/tutorial-working-with-python-in-visual-studio-step-01-create-project?view=vs-2019

Can I disable or suppress warnings about jupyter not being installed by the Jupyter vscode extension?

I'd like to use the Python extension for VSCode,
but it depends on the Jupyter extension (see Q&A here).
I don't use Jupyter on most of my projects and therefore is not installed in my virtual environment.
This causes the Jupyter extension to keep popping up a warning which cannot be dismissed
that it "Failed to start a session" (because Jupyter is not installed).
Is there a setting in the extension that I have overlooked to suppress this warning?
Could you try turning the setting Jupyter->Disable Jupyter Auto Start to true? We have code that tries to autostart a jupyter server or kernel (if you used it before) early. Turning this off should suppress the prompt.
File > Preferences > Settings
Now expand "Text Editor"
"Suggestions"
"Edit in Settings.json"
Now you can disable all notifications or only for an extension.

how to disable jupyter editor in vscode

like the title mentioned, how to disable jupyter editor in vscode?
every time,I want to new a file just for text or markdown,I do not like to appear a choice between two, but just default for the inner editor applied by vscode. and how can I configure this.
for right now,I never need to use jupyter notebook.
It seems to be appeared unexpected after vscode update or installed some python package.
This can be disabled by python.dataScience.useNotebookEditor if you are using the Python extension.
Source: https://github.com/microsoft/vscode/issues/103526
Update:
You also need the Jupyter extension along with Python extension for VS Code. The setting key has been renamed from python.dataScience.useNotebookEditor to jupyter.useNotebookEditor^update
With the July/August 2021 introduction of the new Native Notebook Support in VS Code, the answers involving your settings.json are now obsolete. Now the Notebook editor will be used to open .*ipynb files even if you've never installed the Python or Jupyter extensions.
However, you can open a *.ipynb file in the regular text editor by right-clicking on the file in the VS Code File Explorer, doing "Open With", and then selecting the "Text Editor".