SageMath and Python on Jupyter

SageMath 是一个开源免费的数学软件,综合了大量的开源数学软件,用Python当做软件基本语言。因此,可以在使用Python的过程中,把SageMath当做一个额外功能模块来用。当然,如果是编程来使用,则这样用就够了。不过,SageMath和Python合起来还可以当做“计算器”来使用。这个时候,就最好有一个图形界面,并且能够把结果也在必要的时候做图形呈现,最好还能够分享。

Jupyter就是这样一个界面环境。

有两个方法可以通过Jupyter来集成使用SageMath和Python。

  1. 第一,安装完成SageMath之后,在SageMath界面下打开Jupyter。例如,$./SageMath/sage -n jupyter。前面的SageMath是SageMath的安装目录。SageMath自带了Jupyter,因此,不用重新安装Jupyter。
  2. 第二,单独安装Jupyter和SageMath。在Jupyter界面下打开SageMath。为了能够让Jupyter知道SageMath在哪里,我们需要安装一个Jupyter拓展包,通过下面的命令:$sudo jupyter kernelspec install SageMath/local/share/jupyter/kernels/sagemath。其中的SageMath是SageMath的安装目录。之后,就可以通过运行jupyter notebook来实现通过Jupyter来使用SageMath和Python了。
  3. 如果你还想在任意的目录下都能够通过运行jupyter notebook来实现通过Jupyter来使用SageMath和Python,则还需要修改路径设定,让系统知道SageMath的sage文件和bin文件存在哪里。例如,通过在.bashrc中增加一行:export SAGE_ROOT=SageMath。其中SageMath是SageMath的安装目录,例如/opt/SageMath。以及添加路径,例如 export Path=SageMath:$PATH 来实现。

    注意,这是linux系统,Python是默认系统性安装的。如果其他系统,可能还需要在Jupyter下配置Python。

    安装一个可以在网上完成这个计算——通过Jupyter来集成使用SageMath和Python——的服务器。甚至可以考虑建一个包含机器学习功能的服务器,例如通过anaconda(可以连接上TensorFlow或者其他机器学习包)。如果使用anaconda则可以采用清华anaconda软件仓库

    如果希望其他用户也能够使用这个带了SageMath内核的jupyter notebook,则还需要安装JupyterHub。