-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation Request: vscode jupyter integration #12
Comments
I've never used VSCode; I just use Jupyter notebook directly when interacting with HASS. It looks like VSCode is providing all the necessary information to launch the kernel, but not in a form that the current kernelspec shim expects. Currently it expects just a json file with all the parameters. What's in the I suspect we need to either update the current kernel shim to allow the VSCode-style of arguments, or make a new shim for VSCode. I guess I should start by trying out VSCode. Where in VSCode do you select a Jupyter kernel? |
I installed VSCode and I got the same error as you did. I searched the vscode-python source and couldn't find where that error message is coming from. Unfortunately there's almost no documentation for Jupyter kernels. The pyscript one works with Jupyter notebook, console and lab. Someone who knows VSCode is going to have to figure out how it tries to launch the kernel, since it isn't the same way Jupyter does. Unfortunately, pasting the Jupyter URL doesn't work for me. That would be a decent workaround; not sure why it doesn't work. When I paste the URL, hitting "Enter" does nothing - the dialog stays and there is no visible error or effect. Also, in looking at the VSCode python setup options, I see there is a setting for |
Ooooh. I had that same problem at first (pasting the URL doing nothing). Trying to remember how I resolved it.... |
I think the "URL does nothing" issue was the result of my URL not changing. If the kernel breaks and you want to retry with the same URL, even though it looks like it's changing (because the box contains something else to begin with) if it's not different from the last time you configured it, it does nothing. I "fixed" this by entering some invalid URL, allowing it to reload the window and fail, and then setting it back to the correct URL. VSCode's Jupyter support seems to be "just enough" to consider it supported, but not very complete. Once it's working, it works well. But getting it there is a pain. Which is a shame because, VSCode is otherwise quite wonderful on every platform I've used it on (MacOS, Ubuntu, and Windows 10). I think I have an idea on why it won't accept the pyscript kernel. I think it expects argv to be in the ["python", "-m", "modulename", "-f", "{connection_file}"] format and fails because of that. This is only a guess based on using other modules and seeing what the error messages are. Adding the "-f" option to the kernel is trivial. But, I've never written a python module so I'm not sure what's involved with that. Though, in general, even without VSCode, the install process for the pyscript kernel would be easier if one could "pip install" it instead of copying files manually. |
I'm going to refactor |
Ok, I've done a first pass at the major refactoring so that it can be a PyPi installable package. I haven't pushed the package to PyPi yet, but you can create the package locally (see the README file). It seems to work ok with Jupyter, but still doesn't work with VSCode. It does get past the earlier error about the arguments, but it doesn't connect and gets a timeout. I did make progress in finding the JavaScript code in VSCode that does the Jupyter connection, but I haven't look at it yet. |
I got as far as confirming the
I did find the code in
but I don't know how to navigate to this code and set breakpoints from inside VSCode. I can get the Chrome debugging window up from inside VSCode (Help -> Toggle Developer Tools), and some core JavaScript is visible, but not this file. I don't know JavaScript nor the tools to debug it, so it's probably not worthwhile for me to pursue this further. |
Thank you for taking it this far! I know Javascript fairly well (a little less than I know Python) so I'll see where I can take it from here. |
One more discovery: around line 132345, there is this:
So VSCode requires a
So the arguments in Currently my kernel shim doesn't take a |
I was able to install the module manually and Jupyter is functioning within VSCode for me now. I only see one Kernel running. However, as you indicated, log.info() does not display in VSCode as it does in Notebook over the web. |
Thanks for testing it! I pushed this change to pyscript master about an hour ago, which should fix Background |
I am not. I am currently running my PR to "detect old attributes". So I need to pull your master into that. I will do so shortly. |
The change is just in |
As expected, this shows a log in VSCode:
This does not...
Thank you for fixing VSCode. So much easier to stick in the same IDE than jumping to the browser. |
I don't see pyscript kernel in VSCode. What am I doing wrong? |
Like many programmers and Home Assistant users, VSCode is my editor of choice. VSCode has Jupyter Notebook functionality builtin. It even supports multiple kernels. However, I get errors when attempting to use it "locally".
If I, however, run
jupyter notebook
on the command line and then paste the URL it provides in to VSCode as the remote server, it works fine.Do you use VSCode when working through Jupyter, or are you using the browser-based application? Do you have any tips to make this work?
The text was updated successfully, but these errors were encountered: