cschwan / sage-on-gentoo

(Unofficial) Gentoo Overlay for Sage- and Sage-related ebuilds
84 stars 26 forks source link

Cannot automatically open Jupyter notebook in a browser #647

Closed strogdon closed 3 years ago

strogdon commented 3 years ago

Tangentially related to #646. I usually don't use the notebook but tried to do so seeing #646. On one machine

$ sage -n jupyter

works as expected and a browser window is automatically opened. However, on another machine I get

$ sage -n jupyter
...
Please wait while the Sage Jupyter Notebook server starts...
[I 19:47:48.021 NotebookApp] Serving notebooks from local directory: /local/sage-git/sage
[I 19:47:48.021 NotebookApp] Jupyter Notebook 6.3.0 is running at:
[I 19:47:48.021 NotebookApp] http://localhost:8888/?token=1d4a9508a789868591fb2736faddf0607f52316b8afa2bbd
[I 19:47:48.021 NotebookApp]  or http://127.0.0.1:8888/?token=1d4a9508a789868591fb2736faddf0607f52316b8afa2bbd
[I 19:47:48.021 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 19:47:48.104 NotebookApp] 

    To access the notebook, open this file in a browser:
        file:///home/steven/.local/share/jupyter/runtime/nbserver-17329-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=1d4a9508a789868591fb2736faddf0607f52316b8afa2bbd
     or http://127.0.0.1:8888/?token=1d4a9508a789868591fb2736faddf0607f52316b8afa2bbd

A browser window is not opened. Instead the contents of file:///home/steven/.local/share/jupyter/runtime/nbserver-17329-open.html are opened in an emacs editor window. The suggested instructions do work but not automatically. So something is not set correctly. But what?

kiwifb commented 3 years ago

Looks like a bad file association. Something in your setup has associated html files with emacs, which is not completely stupid since those are usually editable.

strogdon commented 3 years ago

I thought maybe xdg-open was misbehaving, but not sure if the notebook calls it.

kiwifb commented 3 years ago

I recommend inspection with xdg-mime from xdg-utils https://wiki.archlinux.org/title/Xdg-utils, I think xdg-open has to be involved somehow but it may not be in sage's code but the jupyter code.

kiwifb commented 3 years ago

Actually it could be via dev-python/click a real deep dependency of dev-python/notebook.

strogdon commented 3 years ago

OK, the issue

$ xdg-mime query default text/html
emacs.desktop

This should be google-chrome.desktop. I don't mess around with xdg-* so I'm not sure what set this.

$ xdg-mime default google-chrome.desktop text/html

fixes things. This must be done as a normal user. I'm not sure where it is stored.

strogdon commented 3 years ago

I didn't see your comment relative to dev-python/click. Would that affect a normal user?

kiwifb commented 3 years ago

The arch web page has useful indication as to where it is supposed to be stored and even how to get debug info about it.

The stuff about click is just a way to open stuff across OSes. It is not a big deal but that's one of the point where xdg-open is called. It more than affects normal users, it is probably necessary.