pathbird / poetry-kernel

Python Jupyter kernel using Poetry for reproducible notebooks
MIT License
246 stars 7 forks source link

Is it possible to make poetry-kernel work with JupyterHub? #6

Open MsLimon opened 2 years ago

MsLimon commented 2 years ago

Hi!

We have a multi-user JupyterHub instance and we would like to use your library. So far we have only been able to see the poetry-kernel button in the kernel selection screen by installing poetry kernel at the user level (if we install poetry kernel from the user that launches JupyterHub, the root user, the button does not show). But the problem that we have is that when we press the poetry button and create a new notebook in a folder with a poetry project (and ipykernel installed), the kernel is never connected so no code can be executed. The generated logs are the following:

Apr 26 15:30:26 labs-ubuntu-20-04 python3[446728]: [I 2022-04-26 15:30:26.298 SingleUserLabApp restarter:66] AsyncIOLoopKernelRestarter: restarting kernel (2/5), new random ports
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]: Traceback (most recent call last):
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:   File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:     return _run_code(code, main_globals, None,
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:   File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:     exec(code, run_globals)
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:   File "/home/marta/.local/lib/python3.8/site-packages/poetry_kernel/__main__.py", line 68, in <module>
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:     main()
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:   File "/home/marta/.local/lib/python3.8/site-packages/poetry_kernel/__main__.py", line 37, in main
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:     proc = subprocess.Popen(cmd)
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:   File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:     self._execute_child(args, executable, preexec_fn, close_fds,
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:   File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]:     raise child_exception_type(errno_num, err_msg, err_filename)
Apr 26 15:30:26 labs-ubuntu-20-04 python3[1028846]: FileNotFoundError: [Errno 2] No such file or directory: 'poetry'

This looks like poetry is not being found by the library although it is indeed installed both at the root and user level. Is there a way to solve this? Or is this case out of the scope of the library for now?

rmnvncnt commented 1 year ago

I have the same issue. I can select the Poetry kernel while running a notebook, but the kernel fail to connect. Jupyterhub logs state a 404 error : kernel does not exist.

I found an alternative solution for single user environments : poetry run python -m ipykernel install --user --name myenv then restart the server.

twavv commented 1 year ago

Hmmm I'm not sure that your issue (@rmnvncnt) is the same as the OP. Can you include some of the server side logs?

@MsLimon I know this is a few months past when you posted your original issue, but it looks like poetry is just not on the PATH. This project doesn't actually depend on Poetry (in the Python sense of "this package does not import poetry), it just assumes the poetry executable is available.

To debug you might want to make sure you can run poetry from the command line, then see what which poetry spits out and make sure it's on the PATH for the Jupyter notebook server. How the PATH is set is very dependent on how you've set things up so I can't really provide any more guidance than that.

One option could be to make this project directly depend on Poetry, but I'm a little bit resistant to that since it might use a different version of Poetry than the actual project would use (e.g., the version that poetry-kernel refers to is older than what you have installed globally).