-
Notifications
You must be signed in to change notification settings - Fork 217
sagejupyter
Remember: if you don't find what you need, or if you'd like to ask a question, then please email [email protected] at any time. We'd love to hear from you! Please include a link (the URL address in your browser) to any relevant project or document, as part of your email.
CoCalc lets you use back-end Jupyter processes, or kernels, such as the languages Python and R, from both Jupyter notebooks and Sage worksheets.
Note: Running Jupyter kernels from a Sage Worksheet is also known as "the Sage worksheet Jupyter bridge."
- Questions about Jupyter notebooks
- I want to use a Jupyter Notebook (with Sage support)
- I want to use my own copy of Jupyter, which is part of my own Python stack
- I want to install the cite2c Jupyter extension, so I can use Zotero
- How do I use Asymptote for vector graphics in a Jupyter notebook?
- How can I install Jupyter's nbextensions configurator?
- How can I customize the default Jupyter kernel or template?
- Questions about Running Jupyter kernels from a Sage Worksheet
- Questions about both interfaces for Jupyter kernels
Click "+New", then enter a filename and click Jupyter Notebook
. This is a complete rewrite from scratch of the classical Jupyter notebook for CoCalc, but enhanced with realtime synchronization that supports multiple simultaneous editors, a TimeTravel slider that lets you browse everything you have done in the notebook, and much much more.
It is possible to switch to the classic Jupyter client any time you have a notebook open. Click the button labeled "Classic Notebook..." just to the right of "TimeTravel" in the notebook. The notebook will be displayed using the classic Jupyter client. Similarly, in the classic Jupyter client, there is a button "Modern Notebook..." at the right end of the toolbar allowing you to switch to the new client. The Modern/Classic Notebook setting will apply to other notebooks in your project as well. More details....
It is also possible to run a standard Jupyter notebook server (no sync, not integrated into the cloud) by going to project settings and clicking on the link labeled "Plain Jupyter Server". Collaborators on your project can securely use the Jupyter notebook server by visiting this link, but nobody else can.
If you want to make a Jupyter notebook that supports Sage, select the SageMath kernel (in the menu, select Kernel --> Change kernel). This will import the Sage library and enable the preparser.
You can install any version of Python you want into your own project -- just download and build it locally, and install Jupyter (and whatever you want) into it. Then, make a directory "bin" in the home directory of your project and put a symlink to your ipython there, e.g.,
cd ~/bin/
ln -s /path/to/your/ipython .
In project settings, restart your project server (just to be sure), then make sure that when you type "ipython" on the command line, you get your Jupyter. Then clicking on existing Jupyter notebooks or creating new ones (through the graphical user interface) should use your copy of Jupyter. It just uses the "Jupyter" that is in the path, since ipython-notebook just sets up some options and runs "ipython notebook." (Look at ~/.smc/ipython-notebook .)
Cite2C IS NO LONGER SUPPORTED: WILL NOT WORK
Note: Due to some unfriendly users launching attacks from CoCalc, you must pay to enable internet access from within your project in order to access online resources like GitHub.
Do the following in a terminal:
git clone https://github.com/takluyver/cite2c.git && cd cite2c && sage install.py
Now when you open a Jupyter notebook, there will be two new buttons at the end of the button bar, which will let you insert citations.
Question: How do I use Asymptote for vector graphics in a Jupyter notebook?
NO LONGER SUPPORTED: WILL NOT WORK
You can copy the file at this link Examples of drawing scientific diagrams with Asymptote in IPython notebook into your CoCalc project and run it.
Notes:
- You may get the message,
UserWarning: %install_ext is deprecated
on installing the IPython magic extension in the first cell. You can still run the rest of the notebook. - To avoid
freeglut (asy): failed to open display ''
error when callingshow()
, add fileconfig.asy
to the directory with the notebook, with these two lines:
import settings;
offscreen=true;
NO LONGER SUPPORTED: WILL NOT WORK
You can install it in your own project. For that, you need internet access enabled or somehow upload the code into your project. Then, install it like this in a terminal (create a new file terminal.term
)
pip install --user --no-deps jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
and restart the Jupyter server in CoCalc
smc-jupyter restart
Then, in order to see the configurator, you have to open an ipynb file. Click on the the "About" button in the top right click on the link there to open the version of jupyter without the synchronization. There, either go to the main page or the one dedicated for the nbextensions. The URL looks like this:
https://cocalc.com/<your_project_id>/port/jupyter/nbextensions
This content has been moved to the CoCalc user manual: https://doc.cocalc.com/jupyter.html
For a quick reminder, sample code is available for opening an Anaconda3 session. In the Sage worksheet toolbar, select Modes > Jupyter bridge.
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
The 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.
You can get a version of this help message from within a Sage worksheet, regardless of default mode, with
%sage
jupyter?
- Raw input hangs the worksheet:
a = raw_input("type here: ")
. - If
default_mode
is enabled for the jupyter mode and a cell starts with a jupyter magic command, the cell needs to start with 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
From any Sage worksheet cell, just type the following to get a full and up-to-date listing.
%sage
print(jupyter.available_kernels())
See https://github.com/sagemathinc/cocalc/wiki/CustomerJupyterKernel for instructions.
Do not hesitate to email THE LINK TO YOUR PROJECT to [email protected] or https://groups.google.com/forum/?fromgroups#!forum/sage-cloud
This Wiki is for CoCalc.com.
A more structured documentation is the CoCalc User Manual.
For further questions, please contact us.