craigbarratt / hass-pyscript-jupyter

Jupyter kernel shim to connect to HASS pyscript
Apache License 2.0
58 stars 10 forks source link

How configure VSCode to work with pyscript? #23

Open tms320 opened 2 years ago

tms320 commented 2 years ago

I have installed pyscript into Home Assistant (HA). It works properly (I can execute python scripts). On my client Windows machine I installed HASS Pyscript kernel shim for Jupyter and set settings in pyscript.conf file. Here is output of jupyter kernelspec list console command:

Available kernels:
python3     C:\Users\trofi\AppData\Roaming\Python\share\jupyter\kernels\python3
pyscript    C:\ProgramData\jupyter\kernels\pyscript

I want to remotely debug my python script /pyscript/test.py located on my HA machine (Ubuntu server). I installed Jupyter extension in VSCode on my Windows machine and created new Jupyter notebook. What are my next steps to connect it to pyscript? If I press this: image I see this: image I don't see pyscript kernel.

tms320 commented 2 years ago

The output of jupyter notebook command is: image

The output of jupyter console --kernel=pyscript command is: image

I can run Jupyter server using python -m notebook command: image It opens this web page: image

But I still don't see pyscript kernel in VSCode...

tms320 commented 2 years ago

If I create new hass pyscript in web interface: image I see the following error(s) in the HA logs: image

andrew-from-toronto commented 1 year ago

I had the same issue with vscode not showing the kernel. I based my fix off of this post on a related issue with a different kernel https://github.com/microsoft/vscode-jupyter/issues/8286#issuecomment-971801528

In short, update the hass pyscript kernelspec to have the full path to where you have python installed. The problem vscode is having is resolving the correct "python" for it to use.

tms320 commented 1 year ago

I edited 'C:\ProgramData\jupyter\kernels\pyscript\kernel.json' file to specify full path to python interpreter:

{
  "argv": [
    "C:\\Users\\trofi\\AppData\\Local\\Programs\\Python\\Python38\\python.exe",
    "-m",
    "hass_pyscript_kernel",
    "-f",
    "{connection_file}"
  ],
  "display_name": "hass pyscript",
  "language": "python"
}

But it didn't help. I still don't see pyscript kernel in VSCode... If I try to select interpreter: image I see this: image What did I miss? Should I start pyscript kernel manually before I run VSCode?

MaFrom commented 10 months ago

I had the same problem, but in the selection there is a possibility to choose 'other kernels' and then it suddenly showed up the hass pyscript kernel for seleciton. Play a little with the import/selection field for the kernel. Unfortunately I cannot reproduce it now.

NodeJSmith commented 3 months ago

In case it helps anyone else, I installed Jupyter PowerToys (ms-toolsai.vscode-jupyter-powertoys) which adds a pane for selecting kernels, and the pyscript one showed up there without issue.

image