janpfeifer / gonb

GoNB, a Go Notebook Kernel for Jupyter
https://github.com/janpfeifer/gonb
MIT License
469 stars 32 forks source link

Unable to get gonb working on Raspberry pi #35

Closed CdtDelta closed 1 year ago

CdtDelta commented 1 year ago

Hi, I have jupyter lab running on a Pi 4 machine. The python part of Jupyter is working, but I'm having issues getting gonb to work. I'm able to run go on the CLI and I can type gonb on the CLI and get the help menu back. But when I try to open a Gonb notebook I get the following error:

Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]: [W 2023-07-11 15:16:55.403 ServerApp] wrote error: "[Errno 2] No such file or directory: 'gonb'"
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     Traceback (most recent call last):
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/sessions/handlers.py", line 89, in post
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         model = await sm.create_session(
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/sessions/sessionmanager.py", line 287, in create_session
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         kernel_id = await self.start_kernel_for_session(
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/sessions/sessionmanager.py", line 345, in start_kernel_for_session
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         kernel_id = await self.kernel_manager.start_kernel(
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/kernels/kernelmanager.py", line 233, in _async_start_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         kernel_id = await self.USERnned_superclass._async_start_kernel(self, **kwargs)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/multikernelmanager.py", line 219, in _async_start_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         raise km.ready.exception()  # type: ignore
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/multikernelmanager.py", line 166, in _add_kernel_when_ready
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         await kernel_awaitable
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_core/utils/__init__.py", line 182, in ensure_async
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         result = await obj
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/kernels/kernelmanager.py", line 773, in wrapped_method
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         raise err
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/kernels/kernelmanager.py", line 740, in wrapped_method
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         out = await method(self, *args, **kwargs)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/kernels/kernelmanager.py", line 842, in start_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         return await super().start_kernel(*args, **kwargs)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/manager.py", line 93, in wrapper
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         raise e
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/manager.py", line 85, in wrapper
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         out = await method(self, *args, **kwargs)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/manager.py", line 401, in _async_start_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         await self._async_launch_kernel(kernel_cmd, **kw)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/manager.py", line 317, in _async_launch_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         connection_info = await self.provisioner.launch_kernel(kernel_cmd, **kw)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/provisioning/local_provisioner.py", line 208, in launch_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         self.process = launch_kernel(cmd, **scrubbed_kwargs)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/launcher.py", line 170, in launch_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         raise ex
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_client/launcher.py", line 155, in launch_kernel
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         proc = Popen(cmd, **kwargs)  # noqa
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         self._execute_child(args, executable, preexec_fn, close_fds,
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         raise child_exception_type(errno_num, err_msg, err_filename)
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     FileNotFoundError: [Errno 2] No such file or directory: 'gonb'
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     The above exception was the direct cause of the following exception:
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     Traceback (most recent call last):
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/tornado/web.py", line 1786, in _execute
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         result = await result
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       File "/home/USER/.local/lib/python3.9/site-packages/jupyter_server/services/sessions/handlers.py", line 107, in post
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:         raise web.HTTPError(500, str(e)) from e
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     tornado.web.HTTPError: HTTP 500: Internal Server Error ([Errno 2] No such file or directory: 'gonb')
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]: [E 2023-07-11 15:16:55.408 ServerApp] {
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       "Host": "HOSTNAME:8888",
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       "Accept": "*/*",
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       "Referer": "https://HOSTNAME:8888/lab/tree/Untitled.ipynb",
Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:       "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"

I just upgraded to 0.7.2 this morning, and the jupyter server is running under the USER account.

If there's any other info you need please let me know.

janpfeifer commented 1 year ago

Oh that's so cool you are running it in Raspberry pi!

From the logs, it seems gonb failed to execute:

Jul 11 15:16:55 HOSTNAME jupyter-lab[49147]:     FileNotFoundError: [Errno 2] No such file or directory: 'gonb'

Would you mind running the following under the user you are going to run JupyterLab on:

$ gonb --install --logtostderr 

And then looking at the same users's file ~/.local/share/jupyter/kernels/gonb ?

There it should have saved the path to the gonb, and it will pick up the same as the one it used to execute gonb from.

One potential issue was that gonb --install was run from a different user than the one running jupyterlab ? I'm not sure, but let me know how it goes -- if something needs fixing I can do it really quick.

Here is installation code, it's very simple:

https://github.com/janpfeifer/gonb/blob/main/kernel/install.go#L27

Another hypothesis is that when gonb --install was executed, gonb was in the path, and when JupyterLab runs, it is not. I probably should save the absolute path to gonb, in line 29 of the file above. So if the test above doesn't work, would you mind manually editing the absolute path to gonb in your ~/.local/share/jupyter/kernels/gonb ? If that fixes it, I'll create a fix to do this automatically.

CdtDelta commented 1 year ago

So the user that I ran the install from is the same user jupyterlab is running under. That was one of the items I checked before posting my original issue. I had problems getting go to run in the past on jupyter with this same set up (the other go project that are out there similar to yours). But I rebuilt my Pi this time around to eliminate anything I may have screwed up in the first go around. Here's the output from the kernel.json file after running $ gonb -install -logtostderr:

{"argv":["gonb","--kernel","{connection_file}","--logtostderr"],"display_name":"Go (gonb)","language":"go","env":{}}

I did a which gonb on the CLI and got:

which gonb
/home/USER/go/bin/gonb

I edited the kernel.json file so it now reads: {"argv":["/home/pi/go/bin/gonb","--kernel","{connection_file}","--logtostderr"],"display_name":"Go (gonb)","language":"go","env":{}}

But now when I open a gonb notebook I get:

Jul 11 15:59:01 HOSTNAME jupyter-lab[49388]: [I 2023-07-11 15:59:01.576 ServerApp] Creating new notebook in
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: I0711 15:59:02.349634   49404 main.go:78] #033[7;39;32m[24d5a0af]#033[0m kernel created
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: E0711 15:59:02.352100   49404 goexec.go:74] #033[7;39;32m[24d5a0af]#033[0m Failed to run `go mod init gonb_24d5a0af`:
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: #033[7;39;32m[24d5a0af]#033[0m 2023/07/11 15:59:02 Failed to create go executor: exec: "go": executable file not found in $PATH
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: failed to run "go mod init gonb_24d5a0af"
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: github.com/janpfeifer/gonb/goexec.New
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: #011/home/USER/go/pkg/mod/github.com/janpfeifer/gonb@v0.7.2/goexec/goexec.go:75
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: main.main
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: #011/home/USER/go/pkg/mod/github.com/janpfeifer/gonb@v0.7.2/main.go:85
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: runtime.main
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: #011/usr/local/go/src/runtime/proc.go:250
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: runtime.goexit
Jul 11 15:59:02 HOSTNAME jupyter-lab[49404]: #011/usr/local/go/src/runtime/asm_arm64.s:1172
Jul 11 15:59:02 HOSTNAME jupyter-lab[49388]: [I 2023-07-11 15:59:02.375 ServerApp] Kernel started: 376913be-1cc7-4d9e-bf0b-d8b01f778285

I also confirmed that Jupyterlab is running under my USER account:

USER 49388 1 4 15:58 ? 00:00:09 /usr/bin/python3 /home/USER/.local/bin/jupyter-lab --config=/home/USER/.jupyter/jupyter_lab_config.py

janpfeifer commented 1 year ago

Ok, I added a fix to install the absolute path to gonb, so this first issue won't happen next time (after the next release).

Now the issue seems to be with your "PATH" variable. First it was not finding gonb. Now it doesn't seem to find the go command. It assume go is in the path, and it seems to be complaining it doesn't find it:

 Failed to create go executor: exec: "go": executable file not found in $PATH

Would you mind adding your path to go and ${GOBIN} (you can read this with go env GOBIN) to your PATH, before executing JupyterLab ?

Now, I could add a test for go being in the PATH during the installation process, but I'm suspecting this wouldn't help you, because you execute jupyter-lab with a different PATH ? Or is it not the case ?

CdtDelta commented 1 year ago

That's the weird part, go AND gonb are both in my path:

$echo $PATH
/home/USER/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin:/home/USER/go/bin
$ which go
/usr/local/go/bin/go
$ which gonb
/home/USER/go/bin/gonb

As far as I know, I'm not executing jupyter-lab with a different path, but TBH I don't know the inner workings of jupyter-lab well enough to determine that. However, it looks like I don't have GOBIN defined, if I do an echo $GOBIN it returns empty.

Looking at the go docs, it doesn't appear that it's needed.

The default location of $GOPATH is $HOME/go, and it's not usually necessary to set GOPATH explicitly. However, if you have checked out the Go distribution to $HOME/go, you must set GOPATH to another location to avoid conflicts. By default, $GOBIN is $GOPATH/bin (or $HOME/go/bin if GOPATH is not set). After installing, you will want to add this directory to your $PATH so you can use installed tools.

janpfeifer commented 1 year ago

Yes, I think not having a $GOBIN defined is fine, it will take the default, as you pointed out.

And I never touched on jupyter-lab, it just always found out everything in the PATH. I'm thinking it has something to do with your installation/configuration.

Would you be comfortable cloning a branch of gonb and running that instead ? I could do a version that check for the go binary first thing, and if it doesn't find it, it prints out the PATH, so we would know for sure ?

janpfeifer commented 1 year ago

So version that will check for go at the start, and print out the PATH is in https://github.com/janpfeifer/gonb/tree/gopath.

And I think you can do this with:

git clone https://github.com/janpfeifer/gonb.git
git switch gopath
go run . --install --logtostderr

And then try JupyterLab again. It should print out the PATH ...

janpfeifer commented 1 year ago

Here is what it changes btw:

https://github.com/janpfeifer/gonb/commit/e5468b9e6f99f10a0b3057fc0aca2d9f5dd9818d

CdtDelta commented 1 year ago

Yeah looks like the PATH is different when it's running the service:

Jul 11 16:45:48 HOSTNAME jupyter-lab[50675]: F0711 16:45:48.037220   50675 main.go:79] #033[7;39;32m[4bc75d92]#033[0m Failed to find path for the `go` program: exec: "go": executable file not found in $PATH
Jul 11 16:45:48 HOSTNAME jupyter-lab[50675]: Current PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
CdtDelta commented 1 year ago

I figured it out....I needed to add the following to the startup script for the jupyter service:

Environment="PATH=$PATH:/usr/local/go/bin:/home/USER/go/bin"

Once I made that change it looks like it's working now. I was able to run the Hello World sample from the tutorial.

janpfeifer commented 1 year ago

Cool! Enjoy, and let me know if you find any other issues!