kernel connection issues when using Jupyter Notebook extension (within VS Code) - python

It's been a little over a month since I'm using Jupyter notebooks, as an inbuilt extension within Visual Studio Code, and am pretty satisfied with it. However, recently I've been noticing that sometimes for no particular reason, I get a "direct kernel connection broken" error message when I attempt to run the specific cell upon which I'm working at that moment.
I do understand that this might be due to some errors that regularly creep up in my code, but something that I've noticed is that, say for instance that a particular snippet of the code that I've written is buggy. When I run the snippet in the traditional Jupyter Notebook (via my power shell, hosted as a web-based browser application) it shows the nature of the error, and where exactly has it occurred in the body of the program. For the VS Code based Jupyter Notebook extension, it does nothing of that sort and just displays a "Direct kernel connection broken" error message.
I have tried everything - from interrupting the kernel by toggling the red square key to restarting the kernel with the help of the green 'reload' key, but nothing seems to change. Occasionally during this issue, If close and open VS Code, or start coding in a new blank notebook, then this small trick does seem to return the kernel state back to normal. Nevertheless, I'm growing increasingly tired of this temporary fixture and was hoping to fix this issue permanently.
Edit: For further clarification, I have added two pictures for comparison. Both the snapshots are of the same snippet of code. The first picture is of my code running on a traditional Jupyter Notebook ( and it seems to work fine ).
The second picture is a snapshot of the same code snippet, running on VS Code's Extension for Jupyter Notebook.
For further information, kindly refer to the comments below.

Related

How to Fix VSCode Syntax Highlighting for Variables Python

In VSCode, my syntax highlighting for variables occasionally disables. After experimentation, it seems to happen mostly when I'm working on WSL. I haven't found a solid way to recreate it, but I've noticed it happening (not all the time, but sometimes) when performing any action that would temporarily render the variable as plaintext/not a variable. For example, temporarily removing the "=" when defining the variable.
To fix it, I can restart/reload VSCode, but it just gets pretty inconvenient considering it happens once every 30 minutes, if not more often. My theme is Dark+ and it normally looks like the first image (blue highlighted variables), but whenever this bug happens, it looks like the second (unhighlighted; white text).
It also happens when defining functions. Not sure if it happens to anything else at this point.
I've tried resetting my VSCode, reinstalling all extensions, deleting the "Code" folder in %appdata%, as well as deleting ".vscode" in %userprofile%.
When I hover over the variable, it is still recognized as a variable; it just is not highlighted.
My extensions are:
C/C++
C#
Discord Presence
GitHub Pull Requests and Issues
gitignore
HTML CSS Support
isort
Jupyter
Jupyter Cell Tags
Jupyter Keymap
Jupyter Notebook Renderers
Jupyter Slide Show
Live Server
Pylance
Python
GitHub Codespaces
WSL
What it looks like when the bug happens
What it should look like

jupyter notebook slow at responding to updates in code or text information

So I have a project that has multiple files regular python, and I'm using a jupyter lab python file as the 'main' file that imports and runs all the rest of the code. But if I make changes to those python files, the jupyter lab file does not automatically respond to updates in those files, and it takes a long time before the code runs properly with the updates.
The main problem is that I have a text file that I constantly update, and the jupyter lab file reads from that, but it takes forever before the changes in the text file are actually noticed and the code runs off that. Is this just a known issue with jupyter lab or?
There is no code so is difficult to know what is happening here. But how the Jupyter environ "notice" these changes? You must to re run de code again and must to consider than Jupyter maintain the vars in memory until the kernel is restarted (because the garbage collector of Python).
I've tried to erase the variables with del but always Jupyter maintain a reference to the old value (I don't know why) for that reason I try to use my code inside of function's scope in this way the variable dies when the function is done. This is the only way I found to deal with this problem.
I always try work with functions because is hard to debug a code in Jupyter with old variables values.

Using plotly in WSL changes the font (console window changes to raster), and won't work at all in VSCode

I've attempted to work a bit more in WSL recently (I've got the most up-to-date version of WSL2 and the Windows 11 insider beta, both of which I updated today)
Everything works great! But plotly has been giving me issues. When I run it from within VSCode (making sure Python Interpreter is set to my correct environment), it spits out the following error:
tcgetpgrp failed: Not a tty
It then opens a tab in my default browser, but it just hangs until eventually failing to connect
Alternatively, if I run it directly from the WSL console (no VScode), it still gives the same error as above, but it DOES correctly open a window in my web browser. It also, for some reason, changes the font of the console?
I'm not 100% sure what the problem is here. I've used WSL for awhile, and never had any issues with displaying plots and things as needed (though, historically, I've used matplotlib... this is the first time I've tried using plotly, but I've used it without problem on native linux and native windows).
Has anyone else had this issue? Or one similar to it? Any idea on what might be wrong?
Figured this out after a bit of reading on other projects that use plotly. The fix is actually very simple, and just requires adding:
export BROWSER="/mnt/c/path/to/browser.exe"
To your ~/.bashrc file. For example, for me this was:
export BROWSER="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"

How to get rid of repetitive 'Modify Setup' pop-ups when using Jupyter notebooks in VS Code?

Lately, I've been running some Jupyter notebooks in VS Code, and I've been encountering a strange issue: whenever I open such a file, I am bombarded with pop-ups that look like this:
Sometimes a few will pop up; other times it can be upwards of 10 pop-ups. What's bizarre about this is that I already have my VS Code set up properly, and I can run my Jupyter notebooks just fine. I've tried selecting the 'Modify' option and going with the default selections just to make it go away, but no dice. How do I prevent these annoying pop-ups?
Per your new comments, can you check your default settings to see which application is targeted to open .ipynb files? Perhaps .ipynb files are linked to open (strangely) via the Setup exe.

Only open Jupyter lab cell output view

I was recently introduced to JupyterLab and I have seen this video from the documentation, where they introduce the synchronised "output view" of a cell:
https://youtu.be/Asa_ML45HP8
I wonder if it was possible to have "only" this output view as the result of executing a script. So that I could run a Python script, and a browser window would open up and I would see only the output view without the Jupyter interface itself.
Is this or something similar easily feasible already? E.g. by configuring JupyterLab in some way and then starting it?
If I wanted to write an application that does that, do you have hints on where to start from? I presume, that there is a lot of code already present that could be reused.

Categories

Resources