jupyter
jupyter copied to clipboard
Buggy interaction between `envrc` and `with-temp-buffer` usage in `jupyter-command`?
I was trying to debug why I keep getting Can't obtain kernelspecs from jupyter shell command, and I think it has to do with a buggy interaction between how jupyter, jupyter-kernelspec etc are installed in my environment, and how jupyter-command works.
I noticed that (shell-command "jupyter kernelspec list") evaluated in my project buffer returns the right response.
So does (apply #'process-file "jupyter" nil t nil '("kernelspec" "list"))
But
(with-temp-buffer
(apply` #'process-file "jupyter" nil t nil '("kernelspec" "list" ))
)
produces an error about missing jupyter-kernelspec. I think this is because ipykernel is installed in my virtual environment, and I have https://github.com/purcell/envrc, which sets up the right paths in my project buffers so that jupyter-kernelspec functions correctly.
But with-temp-buffer happens outside this, and doesn't find the right path/environment. Do you have a suggestion for how to fix this situation?
Caveat:I'm not an elisp expert, so I could have misunderstood something above. Thanks for your work on this package!
Actually here's a discussion about this exact topic: https://github.com/purcell/envrc/issues/12#issuecomment-770330324
You can fix this with the advice from envrc if you are using envrc (or use inheritenv directly).
(advice-add 'jupyter-command :around #'envrc-propagate-environment)
Example with use-package:
(use-package jupyter-repl
:defer t
:config
(advice-add 'jupyter-command :around #'envrc-propagate-environment))
There are some advised functions in envrc repository
I just ran into this issue myself. I think the recommended long-term fix from envrc is for emacs-jupyter to use https://github.com/purcell/inheritenv
@dvzubarev that doesn't seem to work for me. jupyter-command) works as advertised, but other commands don't seem to respect it, such as (jupyter-available-kernelspecs)