hass-pyscript-jupyter icon indicating copy to clipboard operation
hass-pyscript-jupyter copied to clipboard

How configure VSCode to work with pyscript?

Open tms320 opened this issue 3 years ago • 6 comments

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 avatar Sep 12 '22 18:09 tms320

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 avatar Sep 13 '22 17:09 tms320

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

tms320 avatar Sep 13 '22 18:09 tms320

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.

andrew-from-toronto avatar Oct 02 '22 02:10 andrew-from-toronto

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?

tms320 avatar Oct 09 '22 08:10 tms320

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.

MaFrom avatar Nov 07 '23 08:11 MaFrom

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

NodeJSmith avatar May 19 '24 18:05 NodeJSmith