macOS に Maxima-Jupyter をインストールする

以下を参考に,macOS (Catalina) に Maxima-Jupyter (Maxima kernel for Jupyter) をインストールします。特に,以下の Maxima で綴る数学の旅の記事は参考になりました。実際に Ubuntu 20.04 へのインストール手順の概略を日本語で記載しているものはなかなか見当たらなかったので,この記事にインスパイアされて,macOS でもインストールできることを確認しました。

Homebrew

Homebrew を使えるようにしておきます。そして,

brew update; brew upgrade

Python

brew install python3
pip3 install jupyter jupyterlab

なお,macOS では,/etc/paths の最初に以下を付け加えると,’3’ をつけ忘れても大丈夫。

% cat /etc/paths
/usr/local/opt/python@3.8/libexec/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
% python -V
Python 3.8.5

% python3 -V
Python 3.8.5

% pip -V
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

% pip3 -V
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

下準備

brew install sbcl gpg zmq gnuplot

Maxima

brew install maxima でインストールしてはダメ(これで引っかかって随分悩んでた)。 configure オプションを変更してソースからコンパイル・インストール。

brew edit maxima

Formula/maxima.rb の以下の “--enable-sbcl-exec” の行をコメントアウトし,保存。

      "--enable-sbcl",
#     "--enable-sbcl-exec",
brew install maxima -s  #(-s をつけて,ソースからコンパイル)

quicklisp

Quicklisp beta の Installation を参照。

~/ でもいいが,不用意にデリートして後で困らないように ~/Library に保存してみる。

cd ~/Library

curl -O https://beta.quicklisp.org/quicklisp.lisp
curl -O https://beta.quicklisp.org/quicklisp.lisp.asc
gpg --verify quicklisp.lisp.asc quicklisp.lisp

sbcl --load quicklisp.lisp
...
To continue, evaluate: (quicklisp-quickstart:install)
...
* (quicklisp-quickstart:install)
...
NIL
* (ql:system-apropos "vecto")
...
NIL
* (ql:quickload "vecto")
...
("vecto")
* (ql:add-to-init-file)
...
#P"/Users/quicklisp/.sbclrc"
* (quit)

Maxima-Jupyter

git clone https://github.com/robert-dodier/maxima-jupyter.git
cd maxima-jupyter/
maxima
(%i1) load("load-maxima-jupyter.lisp");
(%i2) jupyter_install();
(%i3) quit();

(%i2) のバリエーションについては,以下の記述を参考に。

After the install script has loaded then install using one of the kernel types.

User specific Quicklisp kernel: jupyter_install();
User specific binary image kernel: jupyter_install_image();
System-wide Quicklisp bundled kernel: jupyter_system_install(true, "pkg/");

After the installation is complete then exit Maxima. For the System-wide installation copy the files in pkg to the system root, i.e. sudo cp -r pkg/* / on Linux. (macOS でも同様)

個人で使うには,jupyter_install();jupyter_install_image(); でよいが,実習室 PC にインストールして教育用に… と思うと,system-wide なインストールが必要で,jupyter_system_install(true, "pkg/");

しかし,system-wide にインストールすると,起動時にコンソールに大量の Warning が出まくる。実行には支障がないようだが,どうしたものかと…

% jupyter console --kernel=maxima
WARNING: System definition file #P"/usr/local/share/maxima-jupyter/software/cl-base64-20150923-git/cl-base64.asd" contains definition for system "cl-base64-tests". Please only define "cl-base64" and secondary systems with a name starting with "cl-base64/" (e.g. "cl-base64/test") in that file.
WARNING: redefining UIOP/PACKAGE::WHEN-PACKAGE-FISHINESS in DEFMACRO
WARNING: redefining UIOP/PACKAGE::NOTE-PACKAGE-FISHINESS in DEFMACRO
WARNING: redefining UIOP/PACKAGE:DEFINE-PACKAGE in DEFMACRO
WARNING: redefining UIOP/COMMON-LISP::LOOP* in DEFMACRO
WARNING: redefining UIOP/COMMON-LISP::COMPATFMT in DEFMACRO
WARNING: redefining UIOP/UTILITY:DEFGENERIC* in DEFMACRO
WARNING: redefining UIOP/UTILITY:DEFUN* in DEFMACRO
WARNING: redefining UIOP/UTILITY:WITH-UPGRADABILITY in DEFMACRO
WARNING: redefining UIOP/UTILITY:UIOP-DEBUG in DEFMACRO
WARNING: redefining UIOP/UTILITY:NEST in DEFMACRO
WARNING: redefining UIOP/UTILITY:IF-LET in DEFMACRO
WARNING: redefining UIOP/UTILITY:WHILE-COLLECTING in DEFMACRO
WARNING: redefining UIOP/UTILITY:APPENDF in DEFMACRO
WARNING: redefining UIOP/UTILITY:LATEST-TIMESTAMP-F in DEFMACRO
WARNING: redefining UIOP/UTILITY:WITH-MUFFLED-CONDITIONS in DEFMACRO
WARNING: redefining PRINT-OBJECT (#<SB-PCL::CONDITION-CLASS UIOP/VERSION:DEPRECATED-FUNCTION-CONDITION> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining UIOP/VERSION:WITH-DEPRECATION in DEFMACRO
WARNING: redefining UIOP/OS:OS-COND in DEFMACRO
WARNING: redefining UIOP/PATHNAME:WITH-PATHNAME-DEFAULTS in DEFMACRO
WARNING: redefining UIOP/PATHNAME:WITH-ENOUGH-PATHNAME in DEFMACRO
WARNING: redefining UIOP/FILESYSTEM:WITH-CURRENT-DIRECTORY in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-SAFE-IO-SYNTAX in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-OUTPUT-FILE in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-OUTPUT in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-INPUT-FILE in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-INPUT in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-NULL-INPUT in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-NULL-OUTPUT in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-TEMPORARY-FILE in DEFMACRO
WARNING: redefining UIOP/STREAM:WITH-STAGING-PATHNAME in DEFMACRO
WARNING: redefining UIOP/IMAGE:WITH-FATAL-CONDITION-HANDLER in DEFMACRO
WARNING: redefining UIOP/LISP-BUILD:WITH-OPTIMIZATION-SETTINGS in DEFMACRO
WARNING: redefining UIOP/LISP-BUILD:WITH-MUFFLED-COMPILER-CONDITIONS in DEFMACRO
WARNING: redefining UIOP/LISP-BUILD:WITH-MUFFLED-LOADER-CONDITIONS in DEFMACRO
WARNING: redefining UIOP/LISP-BUILD:WITH-SAVED-DEFERRED-WARNINGS in DEFMACRO
WARNING: redefining UIOP/RUN-PROGRAM:SLURP-INPUT-STREAM in DEFGENERIC
WARNING: redefining SLURP-INPUT-STREAM (#<SB-PCL:SYSTEM-CLASS COMMON-LISP:FUNCTION> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<BUILT-IN-CLASS COMMON-LISP:CONS> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-PCL:SYSTEM-CLASS COMMON-LISP:STREAM> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER STRING> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER :STRING> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER :LINES> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER :LINE> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER :FORMS> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER :FORM> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER T> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<BUILT-IN-CLASS COMMON-LISP:NULL> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<STRUCTURE-CLASS COMMON-LISP:PATHNAME> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining SLURP-INPUT-STREAM (#<SB-PCL:SYSTEM-CLASS COMMON-LISP:T> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining UIOP/RUN-PROGRAM:VOMIT-OUTPUT-STREAM in DEFGENERIC
WARNING: redefining VOMIT-OUTPUT-STREAM (#<SB-PCL:SYSTEM-CLASS COMMON-LISP:FUNCTION> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining VOMIT-OUTPUT-STREAM (#<BUILT-IN-CLASS COMMON-LISP:CONS> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining VOMIT-OUTPUT-STREAM (#<SB-PCL:SYSTEM-CLASS COMMON-LISP:STREAM> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining VOMIT-OUTPUT-STREAM (#<BUILT-IN-CLASS COMMON-LISP:STRING> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining VOMIT-OUTPUT-STREAM (#<SB-MOP:EQL-SPECIALIZER T> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining VOMIT-OUTPUT-STREAM (#<BUILT-IN-CLASS COMMON-LISP:NULL> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining VOMIT-OUTPUT-STREAM (#<STRUCTURE-CLASS COMMON-LISP:PATHNAME> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining VOMIT-OUTPUT-STREAM (#<SB-PCL:SYSTEM-CLASS COMMON-LISP:T> #<SB-PCL:SYSTEM-CLASS COMMON-LISP:T>) in DEFMETHOD
WARNING: redefining UIOP/RUN-PROGRAM::PLACE-SETTER in DEFMACRO
WARNING: redefining UIOP/RUN-PROGRAM::WITH-PROGRAM-INPUT in DEFMACRO
WARNING: redefining UIOP/RUN-PROGRAM::WITH-PROGRAM-OUTPUT in DEFMACRO
WARNING: redefining UIOP/RUN-PROGRAM::WITH-PROGRAM-ERROR-OUTPUT in DEFMACRO
WARNING: System definition file #P"/usr/local/share/maxima-jupyter/software/pzmq-20200610-git/pzmq.asd" contains definition for system "pzmq-compat". Please only define "pzmq" and secondary systems with a name starting with "pzmq/" (e.g. "pzmq/test") in that file.
WARNING: System definition file #P"/usr/local/share/maxima-jupyter/software/pzmq-20200610-git/pzmq.asd" contains definition for system "pzmq-test". Please only define "pzmq" and secondary systems with a name starting with "pzmq/" (e.g. "pzmq/test") in that file.
WARNING: System definition file #P"/usr/local/share/maxima-jupyter/software/pzmq-20200610-git/pzmq.asd" contains definition for system "pzmq-examples". Please only define "pzmq" and secondary systems with a name starting with "pzmq/" (e.g. "pzmq/test") in that file.
WARNING: redefining DISSECT:WITH-TRUNCATED-STACK in DEFMACRO
WARNING: redefining JUPYTER:START in DEFGENERIC
WARNING: redefining JUPYTER:STOP in DEFGENERIC
jupyter_kernel_start("/Users/kasai/Library/Jupyter/runtime/kernel-75782.json")
/usr/local/lib/python3.8/site-packages/jupyter_console/ptshell.py:98: UserWarning: No lexer found for language 'maxima'. Treating as plain text.
warn("No lexer found for language %r. Treating as plain text." % name)
Jupyter console 6.1.0

maxima-jupyter: a Maxima Jupyter kernel; (C) 2019 Robert Dodier (BSD)
In [1]:

Maxima-Jupyter の Code Highlighting Installation

cd /usr/local/lib/python3.8/site-packages/notebook/static/components/codemirror/mode/
mkdir maxima
cp ~/maxima-jupyter-master/maxima.js maxima/

code (or vim or cot とか,お好きなエディタで) meta.js

  {name: "Mathematica", mime: "text/x-mathematica", mode: "mathematica", ext: ["m", "nb"]},
+ {name: "Maxima", mime: "text/x-maxima", mode: "maxima", ext: ["mac", "max"]},
  {name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]},
cd /usr/local/lib/python3.8/site-packages/pygments/lexers
cp ~/maxima-jupyter-master/maxima_lexer.py .

code  (or vim or cot とか,お好きなエディタで) _mapping.py

  'MatlabSessionLexer': ('pygments.lexers.matlab', 'Matlab session', ('matlabsession',), (), ()),
+ 'MaximaLexer': ('pygments.lexers.maxima_lexer', 'Maxima', ('maxima', 'macsyma'), ('*.mac', '*.max'), ()),
  'MiniDLexer': ('pygments.lexers.d', 'MiniD', ('minid',), (), ('text/x-minidsrc',)),

使用例

Jupyter notebook 環境で,Web ブラウザをフルスクリーン・エディタにして Maxima が使えるのはありがたい。定数や関数の定義,描画結果も保存しておけるしね。