DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

SageMath Notes


Running as Linux Server

Download sagemath binary package file sage-8.1-Ubuntu_16.04-x86_64.tar.bz2 (version 8.1 for Ubuntu 16.04 x64 platform) from tsinghua mirror. Extract it to ~/apps. So we get $SAGE_HOME=$HOME/apps/SageMath. Run ./sage for initial compilation and starting the REPL.

After that add the following lines to $SAGE_HOME/local/etc/jupyter/jupyter_notebook_config.py:

c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False

Then start sage server with ./sage -n jupyter, and open http://<server-ip>:8888/?token=... in your browser (the exact address can be found in the console output), the SageMath 8.1 kernel can be seen in the New dropdown list.

If you don't want to modify the config file, start the server with ./sage -n jupyter --ip '*' (but I don't know how to specify the open_browser to False in command line).

Notice SageMath can't use Anaconda Python. If you setup your system to use Anaconda Python by adding the following line into ~/.zshenv or ~/.bashrc:

export PATH="$HOME/apps/miniconda3/bin:$PATH"

You will get the error below: RecursionError: maximum recursion depth exceeded during compilation.

To fix it ,start SageMath server like this: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games ./sage -n jupyter

A Demo

Create a new notebook with kernel SageMath 8.1, and input the following lines:

eqn = x**3 + sqrt(2)*x + 5 == 0
pretty_print(eqn)
latex(eqn)
res = solve(eqn, x)[0].rhs()
pretty_print(res)
plot([x*exp(-n*x^2)/.4 for n in [1..5]], (0, 2), aspect_ratio=.8)

Ref:

Running a notebook server



Published

Apr 9, 2018

Last Updated

Apr 9, 2018

Category

Tech

Tags

  • jupyter 6
  • linux 158
  • sagemath 1
  • server 10

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor