1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ocaml ?

Last updated at Posted at 2021-11-11

今現在は、
https://colab.research.google.com/github/akabe/ocaml-jupyter/blob/master/notebooks/install_ocaml_colab.ipynb#scrollTo=EIbwAQ2b55bR
これを、ポチ。

以下は、2年前のアーカイブ。

jupyter notebook では ocaml をセットアップする方法がありそうなので、jupyter notebook が使えない場合に GoogleColaboratory で使えたらいいな。

材料

This notebook lets you install an ocaml kernel for colab. In order to get started:Click on "OPEN IN PLAYGROUND".
Run the cell below (this takes multiple minutes).Once the cell has run you can use some ocaml notebook on the same colab instance.
This works by this first installing the necessary apt packages, then installing opam (the ocaml package manager) and building the ocaml compiler, and finally building and installing the ocaml-jupyter kernel.
Note that when the instance gets disconnected, it gets resetted so you have to re-install the kernel.

You can use the use_cache field in the form below in order to store the various binaries on your google drive the first time you run this, then re-installing should be a lot faster (this will require some google drive authentication).

If your colab instance ends up in a bad state, Runtime > Reset all runtimes... should reset it.


1 についての説明。

1 以前の概要。または、GoogleColaboratory で ocaml をセットするという一般的な概要。

Do you know if and how one can use ocaml on colab? In principle there is support for the jupyter protocol…


実践

ウォーミングアップ

  1. をポチり、ocaml カーネルはインストールできたが

IMG_20211111_220138_203.jpg

ocaml のように書いたらエラーになるので、Python のように書いたら、それは Python や。
や、だから。それだとなんなの、結構待ったよ、インストール済むまで。結構待ったよ。10 分。

ということは、ocaml カーネルはインストールできたが、カーネルを切り替えれないというかなしさがあるわけか。

それは、前にも何度かトライ & エラーしたことがある。これは、カーネルを選択する項目が、ipynb ( Google コラボのノートファイルの雛形)にデフォルトでは無いので、付け足すために、ノートファイルをいったんダウンロードして書き足して、アップロードする必要があるということ。Googleコラボの使用上の言葉に置き換えると、ocaml-jupyter というランタイムを選択できるようにすることだ。
ipynb のこの部分に相当する。きっと、たぶん。

 "kernelspec": {
      "display_name": "ocaml-jupyter",
      "name": "ocaml-jupyter"
    }

最短コース

  1. の方は、カーネルは ocaml-jupyter を想定しているノートだけれども、カーネル(使用上はランタイムという呼称)はデフォルトの Python3 なので、つまり、上のように"kernelspec": は設定されている ipynb ファイルになってはいるが、エンジン == ocaml がない状態。
    ということで、こちらのノートを使って、最初のセルに 1) のカーネルをインストールコードを貼りつけて実行する場合は、自分で ipynb ファイル自体を編集する必要はないかもしれない。
    インストールコードは、この bash を読み込んできて実行するようになっている。

2) をドライブにコピーするか、gist に保存してから、1)のセルのコードをコピーして gist から読み込んだ 2) のセルの中にペースとして、ポチ。

  • 見る用途

というか、このファイル。

  • ダウンロード用途

ipynb のファイルは json としてマークダウンのこういうページに貼ると、とてもがんばってブラウザがおちるのでここに貼り付けられないが、見ないとわからないとおもう。

  • 見る用途 / コピーする用途

このファイルを google colab で開くか、または、テキストエディタで開いてみて 1) ipynb ファイルもダウンロードして diff で2つの差分を読んでみたら、何を説明しているのか理解できるかもしれない。"kernelspec":の項目がありや、なしやで google colab 上での挙動が違う。

遠回り
ポチ、ポチ、ポチでトライ&エラー無しでできることだが、それをどういうことか説明するには「iRuby で selenium と chromium のセットアップからテストまで」の箇所をまるごと引用。いや、この R 言語を google colab で使う解説がきれいに説明している。

インストールされていく。

Running the following commands:
apt install libffi-dev libgmp-dev m4
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libgmpxx4ldbl libsigsegv2
Suggested packages:
  gmp-doc libgmp10-doc libmpfr-dev m4-doc
The following NEW packages will be installed:
  libffi-dev libgmp-dev libgmpxx4ldbl libsigsegv2 m4
0 upgraded, 5 newly installed, 0 to remove and 37 not upgraded.
Need to get 693 kB of archives.
After this operation, 2,428 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libgmpxx4ldbl amd64 2:6.1.2+dfsg-2 [8,964 B]
Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libgmp-dev amd64 2:6.1.2+dfsg-2 [316 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic/main amd64 libsigsegv2 amd64 2.12-1 [14.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic/main amd64 m4 amd64 1.4.18-1 [197 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic/main amd64 libffi-dev amd64 3.2.1-8 [156 kB]
Fetched 693 kB in 1s (1,090 kB/s)
Selecting previously unselected package libgmpxx4ldbl:amd64.
(Reading database ... 155219 files and directories currently installed.)
Preparing to unpack .../libgmpxx4ldbl_2%3a6.1.2+dfsg-2_amd64.deb ...
Unpacking libgmpxx4ldbl:amd64 (2:6.1.2+dfsg-2) ...
Selecting previously unselected package libgmp-dev:amd64.
Preparing to unpack .../libgmp-dev_2%3a6.1.2+dfsg-2_amd64.deb ...
Unpacking libgmp-dev:amd64 (2:6.1.2+dfsg-2) ...
Selecting previously unselected package libsigsegv2:amd64.
Preparing to unpack .../libsigsegv2_2.12-1_amd64.deb ...
Unpacking libsigsegv2:amd64 (2.12-1) ...
Selecting previously unselected package m4.
Preparing to unpack .../archives/m4_1.4.18-1_amd64.deb ...
Unpacking m4 (1.4.18-1) ...
Selecting previously unselected package libffi-dev:amd64.
Preparing to unpack .../libffi-dev_3.2.1-8_amd64.deb ...
Unpacking libffi-dev:amd64 (3.2.1-8) ...
Setting up libsigsegv2:amd64 (2.12-1) ...
Setting up libffi-dev:amd64 (3.2.1-8) ...
Setting up m4 (1.4.18-1) ...
Setting up libgmpxx4ldbl:amd64 (2:6.1.2+dfsg-2) ...
Setting up libgmp-dev:amd64 (2:6.1.2+dfsg-2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.3) ...
/sbin/ldconfig.real: /usr/local/lib/python3.7/dist-packages/ideep4py/lib/libmkldnn.so.0 is not a symbolic link



WARNING: apt does not have a stable CLI interface. Use with caution in scripts.


Running the following commands:
(echo "" && yes Y) | (sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh))
## Downloading opam 2.1.0 for linux on x86_64...
## Downloaded.
## Where should it be installed ? [/usr/local/bin] ## opam 2.1.0 installed to /usr/local/bin
## Run this script again with '--restore ' to revert.

Running the following commands:
echo N | opam init --disable-sandboxing --compiler=4.07.1
No configuration file found, using built-in defaults.
Checking for available remotes: rsync and local, git.
  - you won't be able to use mercurial repositories unless you install the hg command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.


<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><><><>
[default] Initialised

<><> Required setup - please read <><><><><><><><><><><><><><><><><><><><><><><>

  In normal operation, opam only alters files within ~/.opam.

  However, to best integrate with your system, some environment variables
  should be set. If you allow it to, this initialisation step will update
  your bash configuration by adding the following line to ~/.profile:

    test -r /root/.opam/opam-init/init.sh && . /root/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

  Otherwise, every time you want to access your opam installation, you will
  need to run:

    eval $(opam env)

  You can always re-run this setup with 'opam init' later.

Do you want opam to modify ~/.profile? [N/y/f]
(default is 'no', use 'f' to choose a different file) 
<><> Creating initial switch '4.07.1' (invariant ["ocaml-base-compiler" {= "4.07.1"} | "ocaml-system" {= "4.07.1"}]) 

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["ocaml-base-compiler" {= "4.07.1"} | "ocaml-system" {= "4.07.1"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
⬇ retrieved ocaml-base-compiler.4.07.1  (https://opam.ocaml.org/cache)
∗ installed ocaml-base-compiler.4.07.1
∗ installed ocaml-config.1
∗ installed ocaml.4.07.1
Done.
# Run eval $(opam env --switch=4.07.1) to update the current shell environment

[WARNING] Running as root is not recommended

Running the following commands:
opam install -y base jupyter=2.7.2
The following actions will be performed:
  ∗ install seq                      base     [required by lwt]
  ∗ install conf-gmp                 3        [required by conf-gmp-powm-sec, zarith]
  ∗ install ocaml-secondary-compiler 4.08.1-1 [required by ocamlfind-secondary]
  ∗ install ocamlbuild               0.14.0   [required by logs, uuidm]
  ∗ install conf-pkg-config          2        [required by conf-zlib, conf-zmq]
  ∗ install ocamlfind                1.9.1    [required by logs, uuidm]
  ∗ install conf-gmp-powm-sec        3        [required by cryptokit]
  ∗ install conf-zmq                 0.1      [required by zmq]
  ∗ install conf-zlib                1        [required by cryptokit]
  ∗ install zarith                   1.12     [required by cryptokit]
  ∗ install topkg                    1.0.4    [required by logs, uuidm]
  ∗ install ocamlfind-secondary      1.9.1    [required by dune]
  ∗ install base-bytes               base     [required by ocplib-endian]
  ∗ install uuidm                    0.9.7    [required by jupyter]
  ∗ install dune                     2.9.1    [required by base, jupyter]
  ∗ install stdlib-shims             0.3.0    [required by ppxlib]
  ∗ install stdint                   0.7.0    [required by jupyter]
  ∗ install sexplib0                 v0.14.0  [required by base]
  ∗ install result                   1.5      [required by dune-configurator, ppx_deriving_yojson]
  ∗ install ppx_derivers             1.2.1    [required by ppxlib, ppx_deriving]
  ∗ install ocaml-syntax-shims       1.0.0    [required by lwt]
  ∗ install ocaml-compiler-libs      v0.12.4  [required by ppxlib]
  ∗ install mmap                     1.1.0    [required by lwt]
  ∗ install easy-format              1.3.2    [required by yojson]
  ∗ install csexp                    1.5.1    [required by dune-configurator]
  ∗ install cppo                     1.6.8    [required by ppx_deriving, lwt, yojson]
  ∗ install base64                   3.5.0    [required by jupyter]
  ∗ install ppxlib                   0.23.0   [required by lwt_ppx, ppx_deriving_yojson]
  ∗ install biniou                   1.2.1    [required by yojson]
  ∗ install dune-configurator        2.9.1    [required by base]
  ∗ install ocplib-endian            1.1      [required by lwt]
  ∗ install ppx_deriving             5.2.1    [required by ppx_deriving_yojson]
  ∗ install yojson                   1.7.0    [required by jupyter]
  ∗ install zmq                      5.1.4    [required by jupyter]
  ∗ install cryptokit                1.16.1   [required by jupyter]
  ∗ install base                     v0.14.0
  ∗ install lwt                      5.4.2    [required by jupyter]
  ∗ install ppx_deriving_yojson      3.6.1    [required by jupyter]
  ∗ install zmq-lwt                  5.1.4    [required by jupyter]
  ∗ install lwt_ppx                  2.0.2    [required by jupyter]
  ∗ install logs                     0.7.0    [required by jupyter]
  ∗ install jupyter                  2.7.2
===== ∗ 42 =====

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved base64.3.5.0  (https://opam.ocaml.org/cache)
⬇ retrieved biniou.1.2.1  (https://opam.ocaml.org/cache)
∗ installed conf-gmp.3
⬇ retrieved base.v0.14.0  (https://opam.ocaml.org/cache)
⬇ retrieved cppo.1.6.8  (https://opam.ocaml.org/cache)
⬇ retrieved cryptokit.1.16.1  (https://opam.ocaml.org/cache)
∗ installed conf-pkg-config.2
∗ installed conf-gmp-powm-sec.3
⬇ retrieved csexp.1.5.1  (https://opam.ocaml.org/cache)
∗ installed conf-zlib.1
⬇ retrieved easy-format.1.3.2  (https://opam.ocaml.org/cache)
∗ installed conf-zmq.0.1
⬇ retrieved jupyter.2.7.2  (https://opam.ocaml.org/cache)
⬇ retrieved logs.0.7.0  (https://opam.ocaml.org/cache)
⬇ retrieved lwt.5.4.2  (https://opam.ocaml.org/cache)
⬇ retrieved dune.2.9.1  (https://opam.ocaml.org/cache)
⬇ retrieved mmap.1.1.0  (https://opam.ocaml.org/cache)
⬇ retrieved lwt_ppx.2.0.2  (https://opam.ocaml.org/cache)
⬇ retrieved ocaml-compiler-libs.v0.12.4  (https://opam.ocaml.org/cache)
⬇ retrieved ocaml-syntax-shims.1.0.0  (https://opam.ocaml.org/cache)
⬇ retrieved ocamlbuild.0.14.0  (https://opam.ocaml.org/cache)
⬇ retrieved ocamlfind.1.9.1  (https://opam.ocaml.org/cache)
⬇ retrieved ocamlfind-secondary.1.9.1  (cached)
⬇ retrieved ocaml-secondary-compiler.4.08.1-1  (https://opam.ocaml.org/cache)
⬇ retrieved dune-configurator.2.9.1  (https://opam.ocaml.org/cache)
⬇ retrieved ppx_derivers.1.2.1  (https://opam.ocaml.org/cache)
⬇ retrieved ocplib-endian.1.1  (https://opam.ocaml.org/cache)
⬇ retrieved ppx_deriving.5.2.1  (https://opam.ocaml.org/cache)
⬇ retrieved ppx_deriving_yojson.3.6.1  (https://opam.ocaml.org/cache)
⬇ retrieved result.1.5  (https://opam.ocaml.org/cache)
⬇ retrieved ppxlib.0.23.0  (https://opam.ocaml.org/cache)
⬇ retrieved sexplib0.v0.14.0  (https://opam.ocaml.org/cache)
⬇ retrieved stdint.0.7.0  (https://opam.ocaml.org/cache)
⬇ retrieved stdlib-shims.0.3.0  (https://opam.ocaml.org/cache)
⬇ retrieved topkg.1.0.4  (https://opam.ocaml.org/cache)
⬇ retrieved uuidm.0.9.7  (https://opam.ocaml.org/cache)
⬇ retrieved yojson.1.7.0  (https://opam.ocaml.org/cache)
⬇ retrieved zarith.1.12  (https://opam.ocaml.org/cache)
⬇ retrieved zmq.5.1.4  (https://opam.ocaml.org/cache)
⬇ retrieved zmq-lwt.5.1.4  (https://opam.ocaml.org/cache)
∗ installed ocamlbuild.0.14.0
∗ installed ocaml-secondary-compiler.4.08.1-1
∗ installed ocamlfind.1.9.1
∗ installed base-bytes.base
∗ installed seq.base
∗ installed ocamlfind-secondary.1.9.1
∗ installed topkg.1.0.4
∗ installed dune.2.9.1
∗ installed uuidm.0.9.7
∗ installed base64.3.5.0
∗ installed cppo.1.6.8
∗ installed csexp.1.5.1
∗ installed easy-format.1.3.2
∗ installed mmap.1.1.0
∗ installed biniou.1.2.1
∗ installed ocaml-compiler-libs.v0.12.4
∗ installed ocaml-syntax-shims.1.0.0
∗ installed ocplib-endian.1.1
∗ installed ppx_derivers.1.2.1
∗ installed result.1.5
∗ installed sexplib0.v0.14.0
∗ installed dune-configurator.2.9.1
∗ installed stdint.0.7.0
∗ installed base.v0.14.0
∗ installed lwt.5.4.2
∗ installed stdlib-shims.0.3.0
∗ installed logs.0.7.0
∗ installed ppxlib.0.23.0
∗ installed yojson.1.7.0
∗ installed lwt_ppx.2.0.2
∗ installed ppx_deriving.5.2.1
∗ installed zarith.1.12
∗ installed ppx_deriving_yojson.3.6.1
∗ installed cryptokit.1.16.1
∗ installed zmq.5.1.4
∗ installed zmq-lwt.5.1.4
∗ installed jupyter.2.7.2
Done.

<><> jupyter.2.7.2 installed successfully <><><><><><><><><><><><><><><><><><><>
=> Please run for registration of ocaml-jupyter kernel:
=> 
=> $ ocaml-jupyter-opam-genspec
=> $ jupyter kernelspec install --name ocaml-jupyter \
=> /root/.opam/4.07.1/share/jupyter
# Run eval $(opam env) to update the current shell environment

[WARNING] Running as root is not recommended

Running the following commands:
echo '#use "topfind";;' >> /root/.ocamlinit
Running the following commands:
/root/.opam/4.07.1/.opam-switch/sources/jupyter.2.7.2/config/ocaml-jupyter-opam-genspec
Generated kernelspec at /root/.opam/4.07.1/share/jupyter/kernel.json

[WARNING] Running as root is not recommended
[WARNING] var was deprecated in version 2.1 of the opam CLI. Use opam var instead or set OPAMCLI environment variable to 2.0.
[WARNING] Running as root is not recommended
[WARNING] var was deprecated in version 2.1 of the opam CLI. Use opam var instead or set OPAMCLI environment variable to 2.0.
[WARNING] Running as root is not recommended
[WARNING] var was deprecated in version 2.1 of the opam CLI. Use opam var instead or set OPAMCLI environment variable to 2.0.

Running the following commands:
jupyter kernelspec install --name ocaml-jupyter /root/.opam/4.07.1/share/jupyter
[InstallKernelSpec] Installed kernelspec ocaml-jupyter in /usr/local/share/jupyter/kernels/ocaml-jupyter

10分くらい。

IMG_20211111_225220_774.jpg

IMG_20211111_231016_074.jpg


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?