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.Tue, 04 Feb 2020 15:24:15 +0100Other than "Jupyter Notebook", is there any other way to use Sage?https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/I am searching for a "compiler" way to use Sage.
Something like TeXShop, I write everything in a single file and press compile to get the results.
Is there an easy way to accomplish this?
Currently I am using the "Notebook" form of Sage which is neat but kind of gets in the way of more complicated programming.
(To be more clear, I am looking for something like an IDE "Integrated development environment", something like PyCharm for Python.)
Thanks a lot.Tue, 10 Jul 2018 09:25:30 +0200https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/Comment by Iguananaut for <p>I am searching for a "compiler" way to use Sage.</p>
<p>Something like TeXShop, I write everything in a single file and press compile to get the results.</p>
<p>Is there an easy way to accomplish this?</p>
<p>Currently I am using the "Notebook" form of Sage which is neat but kind of gets in the way of more complicated programming. </p>
<p>(To be more clear, I am looking for something like an IDE "Integrated development environment", something like PyCharm for Python.)</p>
<p>Thanks a lot.</p>
https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?comment=49782#post-id-49782You can find instructions for configuring PyCharm with sage here: https://ask.sagemath.org/question/39742/make-pycharm-recognise-the-sage-python-interpreter/Tue, 04 Feb 2020 15:24:15 +0100https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?comment=49782#post-id-49782Answer by slelievre for <p>I am searching for a "compiler" way to use Sage.</p>
<p>Something like TeXShop, I write everything in a single file and press compile to get the results.</p>
<p>Is there an easy way to accomplish this?</p>
<p>Currently I am using the "Notebook" form of Sage which is neat but kind of gets in the way of more complicated programming. </p>
<p>(To be more clear, I am looking for something like an IDE "Integrated development environment", something like PyCharm for Python.)</p>
<p>Thanks a lot.</p>
https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?answer=42877#post-id-42877# Ways to use SageMath
## On my computer
- the sage REPL or command-line-interface
- launch Sage in a terminal, wait for the `sage: ` prompt
- type a command then hit the ENTER or RETURN key, get output
- the Jupyter Notebook with the Sage kernel
- ways to launch it
- in a terminal, type `sage -n jupyter`
- or use a launcher such as
- the macOS "Sage app"
- the Windows launcher
- a desktop launcher for Linux
- JupyterLab
- install using `sage --pip install jupyterlab`
- then in the terminal run `sage -n jupyterlab`
- the legacy SageNB notebook
- ways to launch it
- in a terminal, type `sage -n sagenb`
- or in the Sage REPL, type `notebook()`
- or use a launcher
- run a command with `sage -c`
- example: in a terminal, run `sage -c "print(2 + 2)"`
- run a file with extension `.py` or `.sage`
- put the commands in a file such as `myfile.sage` or `myfile.py`
- in the terminal, run `sage myfile.sage` or `sage myfile.py`
- difference between `.sage` and `.py` files
- for `.sage` files, the Sage preparser will be used
- for `.py` files, the Sage preparser will not be used
- use external files
- commands
- `load`, `runfile`, `attach`, `%load`, `%runfile`, `%attach`
- examples
- suppose the file `myfile.sage` contains `def sq(a): return a*a`
- in the terminal, run `sage -c "load('myfile.sage'); print(sq(2))"`
- from another program
- SageTeX, a LaTeX package to use Sage within TeX/LaTeX documents
- [PreTeXt](http://mathbook.pugetsound.edu)
- Cantor
- TeXmacs
- see also
[Interfaces to SageMath in other software](https://wiki.sagemath.org/Interfaces#Interfaces_to_SageMath_in_other_software)
- use OpenMath and SCSCP to exchange mathematical objects
with other mathematics software; work in progress, see
- [Sage Trac ticket 19971: Provide OpenMath interface](https://trac.sagemath.org/ticket/19970)
- [Sage Trac ticket 19970: Provide SCSCP interface](https://trac.sagemath.org/ticket/19971)
## Online
- SageCell
- one-off computations on [SageCell page](http://sagecell.sagemath.org)
- use it to include compute cells in a webpage
- use it with [PreTeXt](http://mathbook.pugetsound.edu)
- CoCalc
- see dedicated item below
- JupyterHub
- there are some deployments of JupyterHub which offer the Sage kernel
- mybinder
- there are some mybinder instances that include Sage
- Sage Notebook servers
- there some deployments of the SageNB notebook;
the one formerly at sagenb.org is no longer active
## CoCalc
- in a CoCalc terminal, run `sage` for the Sage REPL
- use `sage_select` to select which version of Sage to use by default
- CoCalc Sage worksheets (`.sagews`)
- Jupyter Notebook worksheets (`.ipynb`)
- using CoCalc's version of the Jupyter Notebook
- using the Classic Jupyter Notebook
- go to Project preferences and launch Classic Jupyter Notebook;
this will open a separate browser tab which will connect to
your project using the classic Jupyter Notebook protocol;
- allows to use Jupyter Notebook extensions that are not yet
implemented in "CoCalc Jupyter", such as widgets, RISE, ...
## Sage: file formats, data formats
- common file extensions
- .py, .sage, .pyx, .spyx, ...
- .sobj
- SageNB notebook worksheets: .sws
- CoCalc Sage worksheets: .sagews
- .rst, .txt, .html
- converters
- `rst2ipynb`, ...
- viewing, saving, copying, transferring worksheets
## Run shell commands from within sage
- any command starting with `!` is executed as a shell command
- many basic shell commands are available in IPython without `!`:
`ls`, `cd`, `pwd`...
- see also the Python modules `os` and `sys`
## Read from, write to, append to file
- this uses standard Python functionality
- 'r' for read, 'w' for write (overwriting file), 'a' for append
- read from file, all at once or line by line
with open('/path/to/file.txt', 'r') as f:
s = f.read()
with open('/path/to/file.txt', 'r') as f:
for line in f:
<do something with line>
- write to file, bit by bit or line by line
with open('/path/to/file.txt', 'a') as f:
f.write('blah')
f.writelines(['haha', 'hehe', 'hihi'])
- see also the `csv` module for "comma-separated-values" data files
Tue, 10 Jul 2018 10:42:54 +0200https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?answer=42877#post-id-42877Comment by kcrisman for <h1>Ways to use SageMath</h1>
<h2>On my computer</h2>
<ul>
<li>the sage REPL or command-line-interface
<ul>
<li>launch Sage in a terminal, wait for the <code>sage:</code> prompt</li>
<li>type a command then hit the ENTER or RETURN key, get output</li>
</ul></li>
<li>the Jupyter Notebook with the Sage kernel
<ul>
<li>ways to launch it
<ul>
<li>in a terminal, type <code>sage -n jupyter</code></li>
<li>or use a launcher such as
<ul>
<li>the macOS "Sage app"</li>
<li>the Windows launcher</li>
<li>a desktop launcher for Linux</li>
</ul></li>
</ul></li>
</ul></li>
<li>JupyterLab
<ul>
<li>install using <code>sage --pip install jupyterlab</code></li>
<li>then in the terminal run <code>sage -n jupyterlab</code></li>
</ul></li>
<li>the legacy SageNB notebook
<ul>
<li>ways to launch it
<ul>
<li>in a terminal, type <code>sage -n sagenb</code></li>
<li>or in the Sage REPL, type <code>notebook()</code></li>
<li>or use a launcher</li>
</ul></li>
</ul></li>
<li>run a command with <code>sage -c</code>
<ul>
<li>example: in a terminal, run <code>sage -c "print(2 + 2)"</code></li>
</ul></li>
<li>run a file with extension <code>.py</code> or <code>.sage</code>
<ul>
<li>put the commands in a file such as <code>myfile.sage</code> or <code>myfile.py</code></li>
<li>in the terminal, run <code>sage myfile.sage</code> or <code>sage myfile.py</code></li>
<li>difference between <code>.sage</code> and <code>.py</code> files
<ul>
<li>for <code>.sage</code> files, the Sage preparser will be used</li>
<li>for <code>.py</code> files, the Sage preparser will not be used</li>
</ul></li>
</ul></li>
<li>use external files
<ul>
<li>commands
<ul>
<li><code>load</code>, <code>runfile</code>, <code>attach</code>, <code>%load</code>, <code>%runfile</code>, <code>%attach</code></li>
<li>examples
<ul>
<li>suppose the file <code>myfile.sage</code> contains <code>def sq(a): return a*a</code></li>
<li>in the terminal, run <code>sage -c "load('myfile.sage'); print(sq(2))"</code></li>
</ul></li>
</ul></li>
</ul></li>
<li>from another program
<ul>
<li>SageTeX, a LaTeX package to use Sage within TeX/LaTeX documents</li>
<li><a href="http://mathbook.pugetsound.edu">PreTeXt</a></li>
<li>Cantor</li>
<li>TeXmacs</li>
<li>see also
<a href="https://wiki.sagemath.org/Interfaces#Interfaces_to_SageMath_in_other_software">Interfaces to SageMath in other software</a></li>
</ul></li>
<li>use OpenMath and SCSCP to exchange mathematical objects
with other mathematics software; work in progress, see
<ul>
<li><a href="https://trac.sagemath.org/ticket/19970">Sage Trac ticket 19971: Provide OpenMath interface</a></li>
<li><a href="https://trac.sagemath.org/ticket/19971">Sage Trac ticket 19970: Provide SCSCP interface</a></li>
</ul></li>
</ul>
<h2>Online</h2>
<ul>
<li>SageCell
<ul>
<li>one-off computations on <a href="http://sagecell.sagemath.org">SageCell page</a></li>
<li>use it to include compute cells in a webpage</li>
<li>use it with <a href="http://mathbook.pugetsound.edu">PreTeXt</a></li>
</ul></li>
<li>CoCalc
<ul>
<li>see dedicated item below</li>
</ul></li>
<li>JupyterHub
<ul>
<li>there are some deployments of JupyterHub which offer the Sage kernel</li>
</ul></li>
<li>mybinder
<ul>
<li>there are some mybinder instances that include Sage</li>
</ul></li>
<li>Sage Notebook servers
<ul>
<li>there some deployments of the SageNB notebook;
the one formerly at <a href="http://sagenb.org">sagenb.org</a> is no longer active</li>
</ul></li>
</ul>
<h2>CoCalc</h2>
<ul>
<li>in a CoCalc terminal, run <code>sage</code> for the Sage REPL</li>
<li>use <code>sage_select</code> to select which version of Sage to use by default</li>
<li>CoCalc Sage worksheets (<code>.sagews</code>)</li>
<li>Jupyter Notebook worksheets (<code>.ipynb</code>)
<ul>
<li>using CoCalc's version of the Jupyter Notebook</li>
<li>using the Classic Jupyter Notebook
<ul>
<li>go to Project preferences and launch Classic Jupyter Notebook;
this will open a separate browser tab which will connect to
your project using the classic Jupyter Notebook protocol;</li>
<li>allows to use Jupyter Notebook extensions that are not yet
implemented in "CoCalc Jupyter", such as widgets, RISE, ...</li>
</ul></li>
</ul></li>
</ul>
<h2>Sage: file formats, data formats</h2>
<ul>
<li>common file extensions
<ul>
<li>.py, .sage, .pyx, .spyx, ...</li>
<li>.sobj</li>
<li>SageNB notebook worksheets: .sws</li>
<li>CoCalc Sage worksheets: .sagews</li>
<li>.rst, .txt, .html</li>
</ul></li>
<li>converters
<ul>
<li><code>rst2ipynb</code>, ...</li>
</ul></li>
<li>viewing, saving, copying, transferring worksheets</li>
</ul>
<h2>Run shell commands from within sage</h2>
<ul>
<li>any command starting with <code>!</code> is executed as a shell command</li>
<li>many basic shell commands are available in IPython without <code>!</code>:
<code>ls</code>, <code>cd</code>, <code>pwd</code>...</li>
<li>see also the Python modules <code>os</code> and <code>sys</code></li>
</ul>
<h2>Read from, write to, append to file</h2>
<ul>
<li>this uses standard Python functionality</li>
<li>'r' for read, 'w' for write (overwriting file), 'a' for append</li>
<li><p>read from file, all at once or line by line</p>
<pre><code>with open('/path/to/file.txt', 'r') as f:
s = f.read()
with open('/path/to/file.txt', 'r') as f:
for line in f:
<do something with line>
</code></pre></li>
<li><p>write to file, bit by bit or line by line</p>
<pre><code>with open('/path/to/file.txt', 'a') as f:
f.write('blah')
f.writelines(['haha', 'hehe', 'hihi'])
</code></pre></li>
<li><p>see also the <code>csv</code> module for "comma-separated-values" data files</p></li>
</ul>
https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?comment=42973#post-id-42973This is ridiculously comprehensive and should be on the main Sage website in a prominent place ...Thu, 12 Jul 2018 19:11:57 +0200https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?comment=42973#post-id-42973Answer by 56phil for <p>I am searching for a "compiler" way to use Sage.</p>
<p>Something like TeXShop, I write everything in a single file and press compile to get the results.</p>
<p>Is there an easy way to accomplish this?</p>
<p>Currently I am using the "Notebook" form of Sage which is neat but kind of gets in the way of more complicated programming. </p>
<p>(To be more clear, I am looking for something like an IDE "Integrated development environment", something like PyCharm for Python.)</p>
<p>Thanks a lot.</p>
https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?answer=49564#post-id-49564If one wants to use Sage in Jupyterlab on macOS Catalina 10.15.1 (19B88), this worked for me:
1. download Sage binaries
2. unpack download
3. move SAGE_ROOT to the desired location
4. set SAGE_ROOT and any other environment variables (e.g. SAGE_KEEP_BUILT_SPKGS) in ~/.zshrc
(a) export SAGE_KEEP_BUILT_SPKGS="yes"
(b) export SAGE_NUM_THREADS=3
(c) export SAGE_ROOT="$HOME/SageMath"
5. Update $PATH by editing /etc/paths Note: You’ll need to use SUDO.
<$HOME>/SageMath/local/bin
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
<$HOME>/SageMath
6. cd $SAGE_ROOT && ./sage -i openssl && ./sage -f python3 && make ssl && sage –pip3 install jupyterlab
when all this is done, **sage -n jupyterlab**, should work.
**Update**: Avoid updating Python packages using pip. I broke the sage kernal in jupyterlab doing this.Wed, 15 Jan 2020 16:58:43 +0100https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?answer=49564#post-id-49564Comment by Emmanuel Charpentier for <p>If one wants to use Sage in Jupyterlab on macOS Catalina 10.15.1 (19B88), this worked for me:</p>
<pre><code>1. download Sage binaries
2. unpack download
3. move SAGE_ROOT to the desired location
4. set SAGE_ROOT and any other environment variables (e.g. SAGE_KEEP_BUILT_SPKGS) in ~/.zshrc
(a) export SAGE_KEEP_BUILT_SPKGS="yes"
(b) export SAGE_NUM_THREADS=3
(c) export SAGE_ROOT="$HOME/SageMath"
5. Update $PATH by editing /etc/paths Note: You’ll need to use SUDO.
<$HOME>/SageMath/local/bin
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
<$HOME>/SageMath
6. cd $SAGE_ROOT && ./sage -i openssl && ./sage -f python3 && make ssl && sage –pip3 install jupyterlab
</code></pre>
<p>when all this is done, <strong>sage -n jupyterlab</strong>, should work.</p>
<p><strong>Update</strong>: Avoid updating Python packages using pip. I broke the sage kernal in jupyterlab doing this.</p>
https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?comment=49567#post-id-49567This has been discussed a few times on [sage-devel](https://groups.google.com/forum/#!forum/sage-devel). Given the ongoing switch to Python 3, which shall enable the upgrade of a lot of Python libraries in Sage (namely `ipython`, `jupyter` *und so weider*...), the addition of an "official" Jupyterlab interface is probably a question of time...Wed, 15 Jan 2020 18:55:09 +0100https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/?comment=49567#post-id-49567