millejoh / emacs-ipython-notebook

Jupyter notebook client in Emacs
http://millejoh.github.io/emacs-ipython-notebook/
GNU General Public License v3.0
1.47k stars 122 forks source link

Jupyter not found under direnv (but actually is found!) #820

Closed nanounanue closed 2 years ago

nanounanue commented 2 years ago

Hi

Trying to run ein:run got my this error:

Debugger entered--Lisp error: (file-missing "Searching for program" "No such file or directory" "jupyter")
  call-process("jupyter" nil (#<buffer  *temp*> nil) nil "notebook" "list" "--json")
  ein:jupyter-process-lines("http://127.0.0.1:8888" "jupyter" "notebook" "list" "--json")
  ein:jupyter-crib-token("http://127.0.0.1:8888")
  ein:notebooklist-token-or-password("http://127.0.0.1:8888")
  ein:jupyter-server-login-and-open(#f(advice-wrapper :after #f(compiled-function (buffer url-or-port) #<bytecode 0x1246e4df10fe56dd>) #f(compiled-function (&rest args2) #<bytecode -0xae29435227dd57f>)))
  ein:run("/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profil..." "~/projects/tec/pensamiento-computacional/codigo/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x1246e4df10fe56dd>) nil)
  funcall-interactively(ein:run "/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profile/bin/jupyter" "~/projects/tec/pensamiento-computacional/codigo/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x1246e4df10fe56dd>) nil)
  command-execute(ein:run record)
  execute-extended-command(nil "ein:run" "ein")
  funcall-interactively(execute-extended-command nil "ein:run" "ein")
  command-execute(execute-extended-command)

This is weird, because a jupyter is created (in 127.0.0.1:8888), the traceback shows that ein found jupyter in the path (in /gnu/store/.... ) but the error is No such file or directory jupyter

The buffer *ein server* shows:

[I 01:01:27.957 NotebookApp] Serving notebooks from local directory: /home/nanounanue/projects/tec/pensamiento-computacional/codigo
[I 01:01:27.957 NotebookApp] Jupyter Notebook 6.3.0 is running at:
[I 01:01:27.957 NotebookApp] http://localhost:8888/?token=f8b4c9a1a22f0a16429e4e5883cd94ddc16dc2215b4652ce
[I 01:01:27.957 NotebookApp]  or http://127.0.0.1:8888/?token=f8b4c9a1a22f0a16429e4e5883cd94ddc16dc2215b4652ce
[I 01:01:27.957 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 01:01:27.959 NotebookApp] 

    To access the notebook, open this file in a browser:
        file:///home/nanounanue/.local/share/jupyter/runtime/nbserver-61768-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=f8b4c9a1a22f0a16429e4e5883cd94ddc16dc2215b4652ce
     or http://127.0.0.1:8888/?token=f8b4c9a1a22f0a16429e4e5883cd94ddc16dc2215b4652ce
[I 01:01:41.089 NotebookApp] 302 GET / (127.0.0.1) 0.690000ms
[I 01:01:41.230 NotebookApp] 302 GET /tree? (127.0.0.1) 0.550000ms

Is this a bug?

nanounanue commented 2 years ago

If I try to run again ein:run I got this error:

Debugger entered--Lisp error: (error "ein:jupyter-server-start: First ‘M-x ein:stop’")
  error("ein:jupyter-server-start: First `M-x ein:stop'")
  ein:run("/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profil..." "~/projects/tec/pensamiento-computacional/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x1246e4df10fe56dd>) nil)
  funcall-interactively(ein:run "/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profil..." "~/projects/tec/pensamiento-computacional/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x1246e4df10fe56dd>) nil)
  command-execute(ein:run record)
  execute-extended-command(nil "ein:run" nil)
  funcall-interactively(execute-extended-command nil "ein:run" nil)
  command-execute(execute-extended-command)

If I run ein:stop afterwards nothing happens.

dickmao commented 2 years ago

Is this a bug?

Probably. I prefaced the call with executable-find (4c52fcd) in the hopes that that's necessary under Nix.

If I run ein:stop afterwards nothing happens.

That's not good. If you know the server is running and M-: (ein:jupyter-server-conn-info) sends nothing to the echo area (minibuffer), that's a problem.

nanounanue commented 2 years ago

Hi! Thank you for your quick response, I will try the fix, I will return

But before try it, the M-: (ein:jupyter-server-conn-info), returns (nil nil) before ein:run (as expected) and returns the url and the login hash (?) i.e. ("http://127.0.0.1:8888" "367fce988bfff335d68af37d3899992fecb97aa3733bea48") (as expected), but ein:stop doesn't do anything (no message in *Messages* or change the value of (ein:jupyter-server-conn-info)

nanounanue commented 2 years ago

I just try it and not luck :(

When I ran M-: (ein:jupyter-server-conn-info) before running ein:run I get:

Debugger entered--Lisp error: (void-function ein:jupyter-server-conn-info) (ein:jupyter-server-conn-info) eval-expression((ein:jupyter-server-conn-info) nil nil 127) funcall-interactively(eval-expression (ein:jupyter-server-conn-info) nil nil 127) command-execute(eval-expression)

and if I ran ein:run, now I got

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  call-process(nil nil (#<buffer  *temp*> nil) nil "notebook" "list" "--json")
  ein:jupyter-process-lines("http://127.0.0.1:8888" "jupyter" "notebook" "list" "--json")
  ein:jupyter-crib-token("http://127.0.0.1:8888")
  ein:notebooklist-token-or-password("http://127.0.0.1:8888")
  ein:jupyter-server-login-and-open(#f(advice-wrapper :after #f(compiled-function (buffer url-or-port) #<bytecode 0x12462915c5acd6dd>) #f(compiled-function (&rest args2) #<bytecode -0xae29c0039cee57f>)))
  ein:run("/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profil..." "~/projects/tec/pensamiento-computacional/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x12462915c5acd6dd>) nil)
  funcall-interactively(ein:run "/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profil..." "~/projects/tec/pensamiento-computacional/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x12462915c5acd6dd>) nil)
  command-execute(ein:run record)
  execute-extended-command(nil "ein:run" "ein")
  funcall-interactively(execute-extended-command nil "ein:run" "ein")
  command-execute(execute-extended-command)

The server is running. and now if run M-: (ein:jupyter-server-conn-info) I got the correct info.

ein:stop is not stopping the server.

Hope this helps

nanounanue commented 2 years ago

Another thing, if I kill the buffers of the project with project-kill-buffers I get:

Kill 5 buffers in ~/projects/tec/pensamiento-computacional/? (y or n) y
Close http://127.0.0.1:8888? (y or n) y
[error] request--callback: peculiar error
[error] request-default-error-callback: http://127.0.0.1:8888/api/shutdown error

In the *Messages* buffer

dickmao commented 2 years ago

When I ran M-: (ein:jupyter-server-conn-info) before running ein:run I get:

You can't do that. That function doesn't get loaded until ein:run autoloads it.

Your general failures suggest you're running off a system that doesn't conform to POSIX process management, like most Windows variants excepting possibly WSL.

I don't believe EIN is for you, but if you want to pursue this, I'd need to see the output of M-x ein:dev-bug-report-template.

nanounanue commented 2 years ago

Thank you for your quick response. I am running GNU/Linux machine with PopOS, but with guix as a package manager, no windows in my life in the last 20 years or so :)

Didn't know about the M-x ein:dev-bug-report-template I will try it and we will see.

Again, I really appreciate the time that you are giving to help me.

dickmao commented 2 years ago

I am running GNU/Linux machine

Then you'd be helping me more by helping me track this down. EIN is admittedly fragile, but the failure to launch you're describing on a GNU/Linux machine is cause for concern.

nanounanue commented 2 years ago

This is the report, hope this helps

Problem description

ein:run fails with:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  call-process(nil nil (#<buffer  *temp*> nil) nil "notebook" "list" "--json")
  ein:jupyter-process-lines("http://127.0.0.1:8888" "jupyter" "notebook" "list" "--json")
  ein:jupyter-crib-token("http://127.0.0.1:8888")
  ein:notebooklist-token-or-password("http://127.0.0.1:8888")
  ein:jupyter-server-login-and-open(#f(advice-wrapper :after #f(compiled-function (buffer url-or-port) #<bytecode 0x12462915c5acd6dd>) #f(compiled-function (&rest args2) #<bytecode -0xae29c0039cee57f>)))
  ein:run("/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profil..." "~/projects/tec/pensamiento-computacional/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x12462915c5acd6dd>) nil)
  funcall-interactively(ein:run "/gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profil..." "~/projects/tec/pensamiento-computacional/" nil #f(compiled-function (buffer url-or-port) #<bytecode 0x12462915c5acd6dd>) nil)
  command-execute(ein:run record)
  execute-extended-command(nil "ein:run" "ein")
  funcall-interactively(execute-extended-command nil "ein:run" "ein")
  command-execute(execute-extended-command)

But the jupyter server is launched.

Also ein:stop doesn't do anything, not even an error message.

Steps to reproduce the problem

Just run ein:run

System info:

("EIN system info"
 :emacs-version
 "GNU Emacs 28.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)"
 :window-system x
 :emacs-variant nil
 :build
 "CONFIG_SHELL=/gnu/store/pwcp239kjf7lnj5i4lkdzcfcxwcfyk72-bash-minimal-5.0.16/bin/bash SHELL=/gnu/store/pwcp239kjf7lnj5i4lkdzcfcxwcfyk72-bash-minimal-5.0.16/bin/bash --prefix=/gnu/store/90imjn2gdzabsw5b5zqn4x891rv2qfk5-emacs-native-comp-28.0.60-190.a344667 --enable-fast-install --with-native-compilation --with-modules --with-cairo --disable-build-details"
 :os
 (:uname
  "Linux sedol-kasparov 5.13.0-7614-generic #14~1631647151~21.04~930e87c-Ubuntu SMP Fri Sep 17 00:24:58 UTC  x86_64 x86_64 x86_64 GNU/Linux
"
  :lsb-release
  "No LSB modules are available.
Distributor ID: Pop
Description:    Pop!_OS 21.04
Release:    21.04
Codename:   hirsute
")
 :jupyter nil
 :image-types
 (svg png gif tiff jpeg xpm xbm pbm)
 :image-types-available
 (svg png gif tiff jpeg xpm xbm pbm)
 :request-backend curl
 :ein
 (:version nil
           :source-dir "/home/nanounanue/.config/emacs/straight/build/ein/")
 :lib
 ((:name "websocket"
         :path "~/.config/emacs/straight/build/websocket/websocket.elc"
         :featurep t
         :version-var websocket-version
         :version "1.12")
  (:name "anaphora"
         :path "~/.config/emacs/straight/build/anaphora/anaphora.el"
         :featurep t
         :version-var nil
         :version nil)
  (:name "request"
         :path "~/.config/emacs/straight/build/request/request.el"
         :featurep t
         :version-var request-version
         :version "0.3.3")
  (:name "deferred"
         :path "~/.config/emacs/straight/build/deferred/deferred.el"
         :featurep t
         :version-var deferred:version
         :version "0.5.0")
  (:name "polymode"
         :path "~/.config/emacs/straight/build/polymode/polymode.el"
         :featurep t
         :version-var nil
         :version nil)
  (:name "dash"
         :path "~/.config/emacs/straight/build/dash/dash.el"
         :featurep t
         :version-var nil
         :version nil)
  (:name "with-editor"
         :path "~/.config/emacs/straight/build/with-editor/with-editor.el"
         :featurep t
         :version-var nil
         :version nil)))

Logs:

ein:log-all:

10:46:39:269: [info] ein:jupyter-server--run: /gnu/store/n8c68d9pk1sh75d6fvlsi3ayrgq5rb03-profile/bin/jupyter notebook --notebook-dir=~/projects/tec/pensamiento-computacional/ --no-browser @#<buffer pensamiento-computacional>
11:00:01:066: [warn] ein:dev-packages: Don’t call me! @#<buffer  *temp*>

ein server:

[I 10:46:39.978 NotebookApp] Serving notebooks from local directory: /home/nanounanue/projects/tec/pensamiento-computacional
[I 10:46:39.978 NotebookApp] Jupyter Notebook 6.3.0 is running at:
[I 10:46:39.978 NotebookApp] http://localhost:8888/?token=3c67f408988df7b2e87a2b7978bd6b7946c0a0fe07335f5c
[I 10:46:39.978 NotebookApp]  or http://127.0.0.1:8888/?token=3c67f408988df7b2e87a2b7978bd6b7946c0a0fe07335f5c
[I 10:46:39.978 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 10:46:39.980 NotebookApp] 

    To access the notebook, open this file in a browser:
        file:///home/nanounanue/.local/share/jupyter/runtime/nbserver-72616-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=3c67f408988df7b2e87a2b7978bd6b7946c0a0fe07335f5c
     or http://127.0.0.1:8888/?token=3c67f408988df7b2e87a2b7978bd6b7946c0a0fe07335f5c
dickmao commented 2 years ago

Thanks, with commit 1e42a2b you should see in the M-x ein:log-pop-to-all-buffer:

[warn] ein:jupyter-process-lines: cannot find jupyter @#<buffer ein-jupyter.el>

instead of the crash you see now. While it's not ideal that jupyter-process-lines cannot find jupyter, your installation seems to get along without needing to.

As for ein:stop not performing, I see you at least get "Close http://127.0.0.1:8888?". If the server refuses to die after that, you'll need to reenact the failure, then repeat M-x ein:dev-bug-report-template, and paste here.

(I like your computer name. I am a fan of both games).

nanounanue commented 2 years ago

It is working perfectly! Thank you so much!

I have an related question, ein actually has a conflict with hs-minor-mode. I had this mode hooked to all the prog-mode buffers, in order to run ein I needed to deactivate it. Do you know how to deactivate it only for ein?

Thanks in advance

dickmao commented 2 years ago

Assuming you hooked it via prog-mode-hook via something like:

(add-hook 'prog-mode-hook #'hs-minor-mode)

this would turn it off for ein:

(add-hook 'ein:notebook-mode-hook (lambda ()
                                    (when (bound-and-true-p hs-minor-mode)
                                      (hs-minor-mode -1))
                                    (remove-hook 'prog-mode-hook #'hs-minor-mode t)))
nanounanue commented 2 years ago

Thank you

I also forgot to mention that ein:stop is working