-
Notifications
You must be signed in to change notification settings - Fork 221
sagejupyter
Use the jupyter
command to launch any installed jupyter kernel from a Sage worksheet
py3 = jupyter("python3")
After that, any cell that begins with %py3
will send statements to the Python3 kernel that you just started. If you want to draw graphics, there is no need to call %matplotlib inline
.
%py3
print(42)
import numpy as np; import pylab as plt
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.show()
You can set the default mode to be your jupyter kernel for all cells in the worksheet: after putting the following in a cell, click the "restart" button, and you have an anaconda worksheet.
%auto
anaconda3 = jupyter('anaconda3')
%default_mode anaconda3
Each call to jupyter() launches its own Jupyter kernel. So you can have more than one instance of the same kernel type in the same worksheet session.
p1 = jupyter('python3')
p2 = jupyter('python3')
p1('a = 5')
p2('a = 10')
p1('print(a)') # prints 5
p2('print(a)') # prints 10
Get a version of this help message from within a sage worksheet, regardless of default mode, with
%sage
jupyter?
Features listed below are demonstrated in sample worksheets at
https://github.com/sagemath/cloud-examples/tree/master/sagews-jupyter.
- Help, with list of available kernels:
jupyter?
. - Execution count:
[n]: 'XYZ'
. pwd
-
ls
with color-coded output - Plot to png.
- Plot to image/svg+xml.
- Display image from local file or URL.
- Ignore python prompt markers.
- Error output with ansi colors.
- Non-blocking output.
- Function docstring with ansi colors.
- Long docstring and
magic
output to scrolling div. - Markdown, including inline and display MathJAX.
- Embed Youtube video.
- Embed web page from external site.
- LaTeX output from Math() and Latex() objects.
- Play audio from local file.
- Play audio from generated data.
- Autocompletion, if supported by jupyter kernel - tested with python, R, and bash.
- Raw input hangs the worksheet:
a = raw_input("type here: ")
. - If
default_mode
is enabled for a jupyter mode and you would like a cell to start with a jupyter magic command, the first line of the cell should be a comment or mode decorator, or the jupyter magic will be interpreted as a sagews mode. - Long docstring and
magic
create scrollable div, but there is no close button. - If the jupyter kernel crashes, it must be restarted manually.
-
%load somefile
- hangs the .sagews - Embedded youtube widget is rendered multiple times.
- ipywidgets are not supported.
-
jupyter?
calls _get_doc() three times
This Uncyclo is for CoCalc.com.
A more structured documentation is the CoCalc User Manual.
For further questions, please contact us.