hass-pyscript-jupyter
hass-pyscript-jupyter copied to clipboard
Instructions not Working for python3.11 in a venv
I am running python3.11 in a venv (on ubuntu 22.04), and in this particular case, the instructions to get hass-pyscript-jupyter to run are not working.
For context, I am running HA core (v2023.08) on Ubuntu 22.04. The most recent HA versions require python3.11, whereas Ubuntu requires 3.10. Thus, I installed python3.11 in venv that HA is running in anyway. Using the instructions, I tried to install hass-pyscript-jupyter inside the same venv, and I ran into the problems described below.
The installation of hass_pyscript_kernel' looked OK, and
jupyter kernelspec listand
jupyter pyscript infogave me the correct answers (pyscript kernel shows up). From within the venv, I can fire up
jupyter notebook, however, I only get python3 as a kernel option and not hass-pyscript-jupyter. Also, when I run
jupyter console --kernel=pyscriptI get the error messages below, which looks like
/usr/bin/python3is being used when it should really be using
/srv/homeassistant/bin/python`. For starters, it says that the pyscript kernelspec cannot be found...
[ZMQTerminalIPythonApp] WARNING | Kernelspec name pyscript cannot be found!
[ZMQTerminalIPythonApp] ERROR | No such kernel named pyscript
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 71, in wrapper out = await method(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 376, in _async_start_kernel kernel_cmd, kw = await ensure_async(self.pre_start_kernel(**kw))
File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 26, in wrapped raise e
File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 23, in wrapped return loop.run_until_complete(future)
File "/usr/lib/python3/dist-packages/nest_asyncio.py", line 81, in run_until_complete return f.result()
File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception.with_traceback(self._exception_tb)
File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step result = coro.send(None)
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 339, in _async_pre_start_kernel self.kernel_spec,
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 169, in kernel_spec self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)
File "/usr/lib/python3/dist-packages/jupyter_client/kernelspec.py", line 292, in get_kernel_spec raise NoSuchKernel(kernel_name) jupyter_client.kernelspec.NoSuchKernel: No such kernel named pyscript
Traceback (most recent call last):
File "/usr/bin/jupyter-console", line 33, in <module> sys.exit(load_entry_point('jupyter-console==6.4.0', 'console_scripts', 'jupyter-console')())
File "/usr/lib/python3/dist-packages/jupyter_core/application.py", line 264, in launch_instance return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/lib/python3/dist-packages/traitlets/config/application.py", line 845, in launch_instance app.initialize(argv)
File "/usr/lib/python3/dist-packages/traitlets/config/application.py", line 88, in inner return method(app, *args, **kwargs)
File "/usr/lib/python3/dist-packages/jupyter_console/app.py", line 136, in initialize self.init_shell()
File "/usr/lib/python3/dist-packages/jupyter_console/app.py", line 103, in init_shell JupyterConsoleApp.initialize(self)
File "/usr/lib/python3/dist-packages/jupyter_client/consoleapp.py", line 365, in initialize self.init_kernel_manager()
File "/usr/lib/python3/dist-packages/jupyter_client/consoleapp.py", line 319, in init_kernel_manager self.kernel_manager.start_kernel(**kwargs)
File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 26, in wrapped raise e
File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 23, in wrapped return loop.run_until_complete(future)
File "/usr/lib/python3/dist-packages/nest_asyncio.py", line 81, in run_until_complete return f.result()
File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception.with_traceback(self._exception_tb)
File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step result = coro.send(None)
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 79, in wrapper raise e
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 71, in wrapper out = await method(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 376, in _async_start_kernel kernel_cmd, kw = await ensure_async(self.pre_start_kernel(**kw))
File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 26, in wrapped raise e
File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 23, in wrapped return loop.run_until_complete(future)
File "/usr/lib/python3/dist-packages/nest_asyncio.py", line 81, in run_until_complete return f.result()
File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception.with_traceback(self._exception_tb)
File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step result = coro.send(None)
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 339, in _async_pre_start_kernel self.kernel_spec,
File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 169, in kernel_spec self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)
File "/usr/lib/python3/dist-packages/jupyter_client/kernelspec.py", line 292, in get_kernel_spec
I actually found the problem. It turned out that the following jupyter-related packages did not get automatically installed in the venv:
jupyter-bundlerextension
jupyter-console
jupyter-nbextension
jupyter-notebook
jupyter-serverextension
jupyter-bundlerextension
Not sure if all those are included, but notably, this includes jupyter-notebook
. Since it wasn't installed in the venv, it must have run the globally installed one, which had the wrong python version. The notebook I fired up from the venv then did not show the hass-pyscript kernel, which was only installed in the venv.
After python -m pip install jupyter-console
, and python -m pip install jupyter-notebook
, etc. from within the venv the both the notebook and the console worked! I hope this will be useful for someone!