Ask Your Question
0

Running Sage on WSL2 doesn't open jupyter notebook

asked 2022-09-28 22:20:50 +0100

arjsavage gravatar image

updated 2022-09-28 22:41:39 +0100

I've installed Sage on a Windows 11 machine. I installed WSL2 and Ubuntu through the Windows Store. I then installed Sage with a package manager.

When I try to run Sage with commands like "sage -n jupyter" or "sage --notebook", it starts Sage, but doesn't automatically open the jupyter notebook in my browser. Instead, it opens a file in a text editor. I can copy the link mentioned in the terminal output (that is produced when I run Sage) into a browser and that works, but I'd like it to open automatically, so that I can create an easy shortcut to start Sage. Following some instructions I found on wiki.sagemath.org, I created a config file using "sage --jupyter notebook --generate-config", and then I opened the config file and changed the option use_redirect_file to False. But it still doesn't work. Any suggestions?

I also can't find the value of SAGE_ROOT. When I execute the command "sage -root", I just get a blank line. When I start sage and execute "SAGE_ROOT" at the sage prompt, it does nothing.

edit retag flag offensive close merge delete

Comments

in the ~/.bashrc file try to add:

# export BROWSER='/mnt/c/Program Files/Google/Chrome/Application/chrome.exe'
export BROWSER='/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
#export BROWSER='/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'

adapt to your prefered Browser

close and re-open Ubuntu

ortollj gravatar imageortollj ( 2022-09-28 22:43:17 +0100 )edit

for the shortcut problem I'm waiting an answer: question on learn.microsoft.com

see also for info:look at this ask sageMath question

ortollj gravatar imageortollj ( 2022-09-28 22:56:54 +0100 )edit

I added

export BROWSER='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'

to the end of ~/.bashrc, since that is where Chrome is located for me. Then I closed and re-opened Ubuntu. That definitely changed something. Running Sage now gives less output. The last line gives the urls to open. (Before it had some other output after that.) And it doesn't open anything in the text editor. But it still doesn't open the browser automatically.

arjsavage gravatar imagearjsavage ( 2022-09-28 23:01:37 +0100 )edit

so the last thing I can propose try to add in jupyter_notebook_config.py with

c.NotebookApp.use_redirect_file = False

import webbrowser
webbrowser.register('firefox', None, webbrowser.GenericBrowser(u'C:\\Program Files\\Mozilla Firefox\\firefox.exe'))
export BROWSER='/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
c.NotebookApp.browser = 'firefox'

adapt to your browser, if it does not work , sorry that I can't help you

tell me if it does not work and I will delete my answer, in order to give someone the opportunity to provide a good answer

what is your Ubuntu version ?

ortollj gravatar imageortollj ( 2022-09-29 00:01:03 +0100 )edit

Somehow I got it to work by reseting my jupyter config file and starting again. I must have been making a typo somewhere. I changed "use_redirect_file" to False in my jupyter config file, then added the "export BROWSER" command to my .bashrc file. Now running sage from Ubuntu launches the browser. But the Window shortcut doesn't work. Based on the question you posted on learn.microsoft.com, I think you're having the same problem. I'm running Ubuntu 22.04.

arjsavage gravatar imagearjsavage ( 2022-09-29 02:56:00 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-09-29 06:34:24 +0100

ortollj gravatar image

updated 2022-09-29 07:13:55 +0100

Ok I re-commute my first answer that I had transformed into a comment back again into an answer ! despite it remains the W11 shortcut problem.But I'm a bit skeptical about getting an answer on the Microsoft site.Before doing my updates(WSL and Ubuntu 20.04 to 22.04 ) my SageMath W11 shortcuts were working.

I suspect that this may be due to a tightening of security measures for W11 ?

in the ~/.bashrc file try to add:

# export BROWSER='/mnt/c/Program Files/Google/Chrome/Application/chrome.exe'
export BROWSER='/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
#export BROWSER='/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'

adapt to your prefered Browser

close and re-open Ubuntu

edit flag offensive delete link more

Comments

I wonder if the shortcut problem is because the shortcut doesn't execute the .bashrc file. When I try running

C:\Users\.....\ubuntu.exe run ~/.bashrc

(which is the same code I used in the shortcut to run sage, but with the call to sage replaced by .bashrc) from a Windows command line, I get a permission denied error.

arjsavage gravatar imagearjsavage ( 2022-09-29 13:04:09 +0100 )edit

I disagree because if I add source ~/.bashrc at the top of my sage_nb.sh then also no browser is started when clicking on the shortcut and I see no error.

ortollj gravatar imageortollj ( 2022-09-29 15:32:37 +0100 )edit

The solution may be in this reading , but for the moment I admit that I do not have the courage to dive into it !

ortollj gravatar imageortollj ( 2022-10-18 06:39:30 +0100 )edit

maybe it is Ubuntu 22.04 which is causing the problem for desktop shortcut ?

WARNING

Starting from Ubuntu 22.04 LTS, Ubuntu on WSL no longer bundled with wslu. Please install the PPA version.

ortollj gravatar imageortollj ( 2022-12-10 19:46:13 +0100 )edit
0

answered 2022-11-18 20:02:05 +0100

cav24 gravatar image

updated 2022-11-18 20:24:18 +0100

The following solved the problem for me:

(1) In the Ubuntu command line, run

sage --jupyter notebook --generate-config

(2) Open the config file. You can access it from within windows by navigating to the appropriate path using \\wsl$\ to access the Ubuntu file system. In my case the path was

\\wsl$\Ubuntu-20.04\home\ [user name]

(3) Search for "c.NotebookApp.use_redirect_file", uncomment that line and adjust it as follows:

c.NotebookApp.use_redirect_file = False

(See here for the original source of this solution.)

edit flag offensive delete link more

Comments

Hi cav24

Could you specify which Windows OS you are using and which Sagemath version and which Ubuntu version, because the solution which consists in adding c.NotebookApp.use_redirect_file = False in jupyter_notebook_config.py was sufficient for W10, but is no longer sufficient for W11.

ortollj gravatar imageortollj ( 2022-11-19 08:49:00 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-09-28 22:20:50 +0100

Seen: 1,429 times

Last updated: Nov 18 '22