Provide way to determine if running in VS Code Interactive Notebook #16034
Replies: 2 comments 1 reply
-
Right now the only way to detect this is to look at the environment of the kernel. It should inherit env variables from VS code. For example, a kernel on my own machine will have these values: We could inject something into the kernel though to make this easier to detect. For example the env variables won't be there if the kernel is remote. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Moved to microsoft/vscode-jupyter#7380 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am a user of and contributor to HoloViz Panel. Panel is a framework for interactive exploratory data analysis and for building powerful analytics apps (see https://awesome-panel.org).
Panel builds on the Bokeh ecosystem and Panel provides full interactivity in the VS Code Interactive Notebook environment if I set
pn.extension(comms='vscode')
at the top of my code. See the Panel - VS Code docs.My pain is that I and the users I develop notebooks for work in many environments Notebook, Labs, VS Code, PyCharm, Colab and deploy to many servers Bokeh/ Panel, Voila, Flask, Django etc. And the line of code
pn.extension(comms='vscode')
should not be added in any environment but the VS Code Interactive Notebook environment.So I need a way to programmatically determine if the code is running in the VS Code Interactive Notebook environment.
Solution
Please tell me how to programmatically from python determine if I am running in VS Code Interactive Notebook or develop something that can tell me.
Thanks
Additional Context
I tried printing
sys.modules
to see if somethingvs code python extension
specific is loaded. But without luck.I have also tried Google and Github to find an answer without luck.
Not working with 3.0
Panel is currently not working in VS Code with jupyter >= 3.0 c.f. bokeh/jupyter_bokeh#131. Some js package needs to be deployed to npm.
Panel and VS Code is a super powerful combination
The below is something you can develop with Panel. It can also run interactively inside Notebooks and VS Code. And it even lets you start additional servers via
.show()
method on Panel objects so that can open and update windows outside of VS Code from the Interactive Notebook. I.e. circumventing the problem of VS Code not really supporting working efficiently with multiple windows".deckgl_binder.mp4
It also has a powerful
--autoreload
function for users for hot reloading of.py
and.ipynb
files. Which makes it super powerful for working with VS Code and Python.Beta Was this translation helpful? Give feedback.
All reactions