jupyter
jupyter copied to clipboard
Can not connect to existing kernel
Possibly related to #464.
#+begin_src python :async yes :session ./gpu-ssh.json
import scanpy
print("Hello World!")
#+end_src
Evaluating the source block gives me this:
org-babel-jupyter-session-key: Need a valid session and a kernel to form a key
If I add a :kernel argument like :kernel python3, then I can see the correct *jupyter-repl[python 3.7.11]-gpu-ssh.json* buffer but the code is not being sent there, possibly because it starts in the background a new python3 local session. In that case, it shows that it can not import my package despite the package being installed in the :session
It seems that the kernel argument should not be mandatory and up to recent version of the package it was not but now something has changed.
Can the changes be rolled back or provide a workaround until a fix?
Installed version: jupyter-20230608.1504
It looks like this is the spot of the code that complains:
(defun org-babel-jupyter-session-key (params)
"Return a string that is the concatenation of the :session and :kernel PARAMS.
PARAMS is the arguments alist as returned by
`org-babel-get-src-block-info'. The returned string can then be
used to identify unique Jupyter Org babel sessions."
;; Take into account a Lisp expression as a session name.
(let ((session (org-babel-read (alist-get :session params)))
(kernel (alist-get :kernel params)))
(unless (and session kernel
(not (equal session "none")))
(error "Need a valid session and a kernel to form a key"))
(concat session "-" kernel)
))
Hardcoding this function with my started session works fine:
(defun org-babel-jupyter-session-key (params)
"*jupyter-repl[python 3.7.11]-./gpu-ssh.json*"
)
I did some bisecting, and for me this issue starts with 11ace8c, which moved org-babel-jupyter-aliases-from-kernelspecs to the org-babel-execute-src-block advice, and persists after 2f14f2e, which moved aliases generation to org-mode-hook.
By the way, I found that moving (org-babel-jupyter-override-src-block "python") after (org-babel-jupyter-aliases-from-kernelspecs) fixes the issue for me. Hope that helps.