ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 21 Sep 2020 19:45:02 +0200how to move from notebook() to jupyterhttps://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/Seems that I missed a lot since I used sage the last time. I had to learn the hard way that notebook() will not work anymore in 9.1. With some hickups I managed to start jupyter using
> sage -n jupyter --ip 127.0.0.1
but the main jupyter page leaves me clueless.
It shows a listing of my sage root directory. How to configure it to look at ~/.sage (which is outside of this tree)? And, asking in advance, how to use my old notebooks? It seems that the notebook() function has changed to export something (for jupyter?), but instead it just complains about "ValueError: History is empty, cannot export". I moved my old .sage dir, the message is not related to the old content.
I didn not find suitable documentation. Where can I find a guide how to move from sageNB to jupyter and how to use it?
thanksTue, 15 Sep 2020 21:14:22 +0200https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/Comment by Sébastien for <p>Seems that I missed a lot since I used sage the last time. I had to learn the hard way that notebook() will not work anymore in 9.1. With some hickups I managed to start jupyter using </p>
<blockquote>
<p>sage -n jupyter --ip 127.0.0.1</p>
</blockquote>
<p>but the main jupyter page leaves me clueless.
It shows a listing of my sage root directory. How to configure it to look at ~/.sage (which is outside of this tree)? And, asking in advance, how to use my old notebooks? It seems that the notebook() function has changed to export something (for jupyter?), but instead it just complains about "ValueError: History is empty, cannot export". I moved my old .sage dir, the message is not related to the old content.</p>
<p>I didn not find suitable documentation. Where can I find a guide how to move from sageNB to jupyter and how to use it?</p>
<p>thanks</p>
https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?comment=53466#post-id-53466An important change from the old sagenb to Jupyter is the notion of "present working directory" which exists in Jupyter notebook (see the description of ticket https://trac.sagemath.org/ticket/17203 which includes a citation of Fernando Perez on the philosophie of the Jupyter notebook which was then named IPython notebook). Each Jupyter notebook lives in a directory and you can choose it by calling `sage -n jupyter` from that directory or by giving it as an option `--notebook-dir=~/path/to/chosen/directory`Wed, 16 Sep 2020 10:57:42 +0200https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?comment=53466#post-id-53466Answer by eric_g for <p>Seems that I missed a lot since I used sage the last time. I had to learn the hard way that notebook() will not work anymore in 9.1. With some hickups I managed to start jupyter using </p>
<blockquote>
<p>sage -n jupyter --ip 127.0.0.1</p>
</blockquote>
<p>but the main jupyter page leaves me clueless.
It shows a listing of my sage root directory. How to configure it to look at ~/.sage (which is outside of this tree)? And, asking in advance, how to use my old notebooks? It seems that the notebook() function has changed to export something (for jupyter?), but instead it just complains about "ValueError: History is empty, cannot export". I moved my old .sage dir, the message is not related to the old content.</p>
<p>I didn not find suitable documentation. Where can I find a guide how to move from sageNB to jupyter and how to use it?</p>
<p>thanks</p>
https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?answer=53464#post-id-53464Run
sage -n export
and look at the section *Convert old notebooks to Jupyter*. You should see the list of your old Sage notebooks (i.e. all those that are stored in ~/.sage). Clicking on any of them will convert it to Jupyter format.
*NB:* it seems that the conversion only works with Sage versions <= 8.9, i.e. with versions that were running Python 2 by default. For instance, you can run Sage 8.9 on [CoCalc](https://cocalc.com/).Tue, 15 Sep 2020 22:00:33 +0200https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?answer=53464#post-id-53464Answer by gg@g for <p>Seems that I missed a lot since I used sage the last time. I had to learn the hard way that notebook() will not work anymore in 9.1. With some hickups I managed to start jupyter using </p>
<blockquote>
<p>sage -n jupyter --ip 127.0.0.1</p>
</blockquote>
<p>but the main jupyter page leaves me clueless.
It shows a listing of my sage root directory. How to configure it to look at ~/.sage (which is outside of this tree)? And, asking in advance, how to use my old notebooks? It seems that the notebook() function has changed to export something (for jupyter?), but instead it just complains about "ValueError: History is empty, cannot export". I moved my old .sage dir, the message is not related to the old content.</p>
<p>I didn not find suitable documentation. Where can I find a guide how to move from sageNB to jupyter and how to use it?</p>
<p>thanks</p>
https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?answer=53492#post-id-53492Thanks for these Tips!
Initially it seemed that 9.1 doesn't have the export function because a) I again have to specify --ip 127.0.0.1 to get rid of an error message but then b) there is nothing for the browser. After struggling with v8.9 (compilation failed on my openSuse, but the Ubuntu tarball did it) I realized that the behaviour is just the same.
That said, it seems to be a command line tool with little documentation on the options.
./sage -n export --ip=127.0.0.1 --list
creates a list of notebooks, e.g.
Unique ID | Notebook Name
-------------------------------------------------------------------------------
_sage_:0 | Welcome to the Sage Tutorial! -- Sage Tutorial v5.11
This works in 8.9 and 9.1 (even if compiled for Python3). From there I'm digging deeper, there seems to be no "batch" conversion. Following [https://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/](https://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/) I did this for a batch conversion of all notebooks, creating descriptive names:
# go to a new space
mkdir ~/.sage/jupyter_notebooks
cd ~/.sage/jupyter_notebooks
# make a list of IDs and worksheet names
/opt/sage-9.1/sage -n export --ip=127.0.0.1 --list > sagenb_list.txt
# prepare the arguments for the conversion
cat sagenb_list.txt | tail -n +3 | awk '{$2="" ; print "--ipynb=\""$0".ipynb\" "$1}' > map_list.txt
# run the conversion (sequentially, use)
cat map_list.txt |xargs -L 1 /opt/sage-9.1/sage -n export
And then started the notebook server with
/opt/sage-9.1/sage -n jupyter --notebook-dir="~/.sage/jupyter_notebooks" --ip=127.0.0.1
to view it in the browser at [http://127.0.0.1:8888/tree](http://127.0.0.1:8888/tree). From my example above, the name of the exported notebook changed to
> _sage_:0 Welcome to the Sage Tutorial! -- Sage Tutorial v5.11.ipynb
Magically I can even open them, but handling seems to be a bit different as well...I'll figure it out. Thanks again! :-) Fri, 18 Sep 2020 17:49:35 +0200https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?answer=53492#post-id-53492Comment by slelievre for <p>Thanks for these Tips!
Initially it seemed that 9.1 doesn't have the export function because a) I again have to specify --ip 127.0.0.1 to get rid of an error message but then b) there is nothing for the browser. After struggling with v8.9 (compilation failed on my openSuse, but the Ubuntu tarball did it) I realized that the behaviour is just the same.</p>
<p>That said, it seems to be a command line tool with little documentation on the options.</p>
<pre><code>./sage -n export --ip=127.0.0.1 --list
</code></pre>
<p>creates a list of notebooks, e.g. </p>
<pre><code>Unique ID | Notebook Name
-------------------------------------------------------------------------------
_sage_:0 | Welcome to the Sage Tutorial! -- Sage Tutorial v5.11
</code></pre>
<p>This works in 8.9 and 9.1 (even if compiled for Python3). From there I'm digging deeper, there seems to be no "batch" conversion. Following <a href="https://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/">https://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/</a> I did this for a batch conversion of all notebooks, creating descriptive names:</p>
<pre><code># go to a new space
mkdir ~/.sage/jupyter_notebooks
cd ~/.sage/jupyter_notebooks
# make a list of IDs and worksheet names
/opt/sage-9.1/sage -n export --ip=127.0.0.1 --list > sagenb_list.txt
# prepare the arguments for the conversion
cat sagenb_list.txt | tail -n +3 | awk '{$2="" ; print "--ipynb=\""$0".ipynb\" "$1}' > map_list.txt
# run the conversion (sequentially, use)
cat map_list.txt |xargs -L 1 /opt/sage-9.1/sage -n export
</code></pre>
<p>And then started the notebook server with</p>
<pre><code>/opt/sage-9.1/sage -n jupyter --notebook-dir="~/.sage/jupyter_notebooks" --ip=127.0.0.1
</code></pre>
<p>to view it in the browser at <a href="http://127.0.0.1:8888/tree">http://127.0.0.1:8888/tree</a>. From my example above, the name of the exported notebook changed to </p>
<blockquote>
<p>_sage_:0 Welcome to the Sage Tutorial! -- Sage Tutorial v5.11.ipynb</p>
</blockquote>
<p>Magically I can even open them, but handling seems to be a bit different as well...I'll figure it out. Thanks again! :-) </p>
https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?comment=53495#post-id-53495Congratulations. Don't hesitate to accept your own answer
as it can help other users who have the same question.Fri, 18 Sep 2020 19:11:59 +0200https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?comment=53495#post-id-53495Comment by gg@g for <p>Thanks for these Tips!
Initially it seemed that 9.1 doesn't have the export function because a) I again have to specify --ip 127.0.0.1 to get rid of an error message but then b) there is nothing for the browser. After struggling with v8.9 (compilation failed on my openSuse, but the Ubuntu tarball did it) I realized that the behaviour is just the same.</p>
<p>That said, it seems to be a command line tool with little documentation on the options.</p>
<pre><code>./sage -n export --ip=127.0.0.1 --list
</code></pre>
<p>creates a list of notebooks, e.g. </p>
<pre><code>Unique ID | Notebook Name
-------------------------------------------------------------------------------
_sage_:0 | Welcome to the Sage Tutorial! -- Sage Tutorial v5.11
</code></pre>
<p>This works in 8.9 and 9.1 (even if compiled for Python3). From there I'm digging deeper, there seems to be no "batch" conversion. Following <a href="https://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/">https://ask.sagemath.org/question/41680/best-way-to-convert-many-notebooks-from-sagenb-to-jupyter/</a> I did this for a batch conversion of all notebooks, creating descriptive names:</p>
<pre><code># go to a new space
mkdir ~/.sage/jupyter_notebooks
cd ~/.sage/jupyter_notebooks
# make a list of IDs and worksheet names
/opt/sage-9.1/sage -n export --ip=127.0.0.1 --list > sagenb_list.txt
# prepare the arguments for the conversion
cat sagenb_list.txt | tail -n +3 | awk '{$2="" ; print "--ipynb=\""$0".ipynb\" "$1}' > map_list.txt
# run the conversion (sequentially, use)
cat map_list.txt |xargs -L 1 /opt/sage-9.1/sage -n export
</code></pre>
<p>And then started the notebook server with</p>
<pre><code>/opt/sage-9.1/sage -n jupyter --notebook-dir="~/.sage/jupyter_notebooks" --ip=127.0.0.1
</code></pre>
<p>to view it in the browser at <a href="http://127.0.0.1:8888/tree">http://127.0.0.1:8888/tree</a>. From my example above, the name of the exported notebook changed to </p>
<blockquote>
<p>_sage_:0 Welcome to the Sage Tutorial! -- Sage Tutorial v5.11.ipynb</p>
</blockquote>
<p>Magically I can even open them, but handling seems to be a bit different as well...I'll figure it out. Thanks again! :-) </p>
https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?comment=53530#post-id-53530Thanks! I couldn't see the buttons on the left side with a white on black layout. I would have never noticed...
I add that the converted notebooks should be marked "Trusted" after opening them for the first time. Then they mostly work as before with very few adjustments (my stuff is from v6.5 and older). Happy to have this tool :-)Mon, 21 Sep 2020 19:45:02 +0200https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?comment=53530#post-id-53530Answer by slelievre for <p>Seems that I missed a lot since I used sage the last time. I had to learn the hard way that notebook() will not work anymore in 9.1. With some hickups I managed to start jupyter using </p>
<blockquote>
<p>sage -n jupyter --ip 127.0.0.1</p>
</blockquote>
<p>but the main jupyter page leaves me clueless.
It shows a listing of my sage root directory. How to configure it to look at ~/.sage (which is outside of this tree)? And, asking in advance, how to use my old notebooks? It seems that the notebook() function has changed to export something (for jupyter?), but instead it just complains about "ValueError: History is empty, cannot export". I moved my old .sage dir, the message is not related to the old content.</p>
<p>I didn not find suitable documentation. Where can I find a guide how to move from sageNB to jupyter and how to use it?</p>
<p>thanks</p>
https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?answer=53465#post-id-53465Expanding on Eric's answer.
Solution 1.
- install Sage built for Python 2 or compile it from source (possible up to Sage 9.1)
- then run `sage -n` which will offer a few choices:
- run the old SageNB
- export all SageNB worksheets (.sws) to Jupyter worksheets (.ipynb)
- run Jupyter Notebook
- or directly run `sage -n export`
Solution 2.
- zip the `.sage` folder that exists in your user account on your computer
- open an account on CoCalc if you don't have one,
- create a new CoCalc project,
- upload the zipped `.sage` to that new CoCalc project
- unzip it there
- in the CoCalc project's settings tab, change "software image" from "default" to "Ubuntu 18.04"
- in a CoCalc terminal in that project, run `sage_select 8.9`
- in a CoCalc terminal in that project, run `sage -n export`
- then download the resulting .ipynb files back to your computerWed, 16 Sep 2020 06:53:53 +0200https://ask.sagemath.org/question/53463/how-to-move-from-notebook-to-jupyter/?answer=53465#post-id-53465