Coder Social home page Coder Social logo

akabe / ocaml-jupyter Goto Github PK

View Code? Open in Web Editor NEW
286.0 12.0 41.0 1.86 MB

An OCaml kernel for Jupyter (IPython) notebook

Home Page: https://akabe.github.io/ocaml-jupyter/

License: MIT License

Shell 0.14% OCaml 50.12% Jupyter Notebook 49.53% Makefile 0.20% Common Lisp 0.02%
ocaml functional-programming jupyter-kernels machine-learning datascience dataanalysis jupyter-notebook jupyter ocaml-kernel ocaml-repl

ocaml-jupyter's Introduction

OCaml Jupyter

Jupyter protocol License CI Sponsor

An OCaml kernel for Jupyter notebook.

This provides an OCaml REPL with a great user interface such as markdown/HTML documentation, LaTeX formula by MathJax, and image embedding.

Screenshot

Getting started

OCaml Jupyter requires the libraries zlib, libffi, libgmp, libzmq 5+. Type one of the following commands suitable for your environment.

# For Debian or Ubuntu:
sudo apt-get install -y zlib1g-dev libffi-dev libgmp-dev libzmq5-dev
# For REHL or CentOS:
sudo yum install -y epel-release
sudo yum install -y zlib-devel libffi-dev gmp-devel zeromq-devel
# For Mac OS X:
brew install zlib libffi gmp zeromq

OCaml Jupyter can be installed by OPAM as follows:

pip install jupyter
opam install jupyter
grep topfind ~/.ocamlinit || echo '#use "topfind";;' >> ~/.ocamlinit  # For using '#require' directive
grep Topfind.log ~/.ocamlinit || echo 'Topfind.log:=ignore;;' >> ~/.ocamlinit  # Suppress logging of topfind (recommended but not necessary)
ocaml-jupyter-opam-genspec
jupyter kernelspec install [ --user ] --name "ocaml-jupyter-$(opam var switch)" "$(opam var share)/jupyter"

If the last command fails due to permission, --user option or sudo is required. You can use ocaml-jupyter kernel by launching Jupyter notebook server:

jupyter notebook

Development version

opam pin add jupyter https://github.com/akabe/ocaml-jupyter.git

Usage

Examples

In addition, many examples (e.g, image processing, voice analysis, etc.) are available at docker-ocaml-jupyter-datascience/notebooks.

These examples are placed in the public domain, e.g., you can edit, copy, and re-distribute with no copyright messages.

Code completion

OCaml Jupyter kernel supports merlin-based code completion. Candidates are shown by Tab key like

Code completion

The kernel uses .merlin file at a notebook directory for completion.

Inspection

Inspection in Jupyter is also achieved by merlin. You can see documentation and type of an identifier by Shift+Tab key like

Inspection

API documentation

OCaml Jupyter includes some sub-packages:

  • jupyter is a core library of OCaml Jupyter. This package is internally used. You don't need it directly.
  • jupyter.notebook is a library to control Jupyter from OCaml REPL in notebooks. This provides dynamic generation of HTML/markdown, and image embedding.
  • jupyter.comm is a library for communication between OCaml notebooks and Jupyter/Web frontend.

NBConvert

OCaml notebooks can be converted to HTML, Markdown, LaTeX, .ml files, etc. using the jupyter nbconvert command. For example, a .ipynb file is converted into a .html file as follows:

$ jupyter nbconvert --to html notebooks/introduction.ipynb
[NbConvertApp] Converting notebook notebooks/introduction.ipynb to html
[NbConvertApp] Writing 463004 bytes to notebooks/introduction.html

For exporting .ml files, we recommend Jupyter-NBConvert-OCaml. It outputs .ml files with Markdown cells as comments. After installation of Jupyter-NBConvert-OCaml, you can use --to ocaml option to export a .ml file:

$ jupyter nbconvert --to ocaml notebooks/introduction.ipynb
[NbConvertApp] Converting notebook notebooks/introduction.ipynb to ocaml
[NbConvertApp] Writing 2271 bytes to notebooks/introduction.ml

Customize kernel parameters

ocaml-jupyter-opam-genspec generates a configuration file like:

$ cat "$(opam var share)/jupyter/kernel.json"
{
  "display_name": "OCaml 4.08.1",
  "language": "OCaml",
  "argv": [
    "/bin/sh",
    "-c",
    "eval $(opam env --switch=4.08.1) && /home/xxxx/.opam/4.08.1/bin/ocaml-jupyter-kernel \"$@\"",
    "-init", "/home/xxxx/.ocamlinit",
    "--merlin", "/home/xxxx/.opam/4.08.1/bin/ocamlmerlin",
    "--verbosity", "app",
    "--connection-file", "{connection_file}"
  ]
}

See ocaml-jupyter-kernel --help for details of command-line parameters in argv. After you edit the file, re-register the kernel:

jupyter kernelspec install --name ocaml-jupyter "$(opam var share)/jupyter"

Installation without OPAM

ocaml-jupyter-opam-genspec depends on OPAM. If you use an other package manager, you need to write kernel.json by hand or use provided suitable way for registering a new kernel (e.g., jupyter module on Nix).

Running OCaml Jupyter on other environments

Binder

OCaml Jupyter can be run on Binder. Click the button to get started: Binder

For more information, see this repository.

Google Colab

OCaml Jupyter can be run on Google Colab. In order to do this you first have to run this Python notebook in your Colab instance. This will install the kernel and after that OCaml notebooks can be used on the same instance.

Sponsors

If you like this project, please support by becoming a sponsor via GitHub Sponsors.

Related work

Many Jupyter kernels for functional programming languages are available such as IHaskell, Jupyter Scala, and Jupyter Rust. IOCaml is another practical OCaml kernel that inspires us, but it seems no longer maintained. OCaml Jupyter kernel differs from IOCaml in

OCaml Jupyter IOCaml v0.4.8
Jupyter protocol v5.2 v3.2
OCaml PPX support Yes No
Session key support Yes No
Code completion Yes Yes
Introspection Yes Yes
User-defined messages Yes No
Stdin Yes No

Another OCaml kernel simple_jucaml seems too simple to use in practice. jupyter-kernel is a library to write OCaml kernels (not a kernel), but OCaml Jupyter kernel does not use this library.

ocaml-jupyter's People

Contributors

314eter avatar adept avatar akabe avatar bladewang avatar chris00 avatar clouds56 avatar dra27 avatar edmcman avatar gridbugs avatar kit-ty-kate avatar laurentmazare avatar mirko-b avatar mseri avatar mt-caret avatar naereen avatar sei-eschwartz avatar slel avatar xclerc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocaml-jupyter's Issues

Unable to load kernel

Hi
I have installed ocaml-jupyter on my fresh version of Ubuntu 18.04. Before installing, I have a previous installation of jupyter notebook.

The problem I face is the following : Jupyter Notebook is unable to connect permantly to the kernel. I get repeatedly the message:

Fatal error: cannot load shared library dlllwt_unix_stubs
Reason: dlllwt_unix_stubs.so: cannot open shared object file: No such file or directory

By the way, the shared library has been installed by opam in my ~/.opam/system/lib/stublibs/ folder.

Thanks for any hint.

Support lwt 4.0.0

Lwt 4.0.0 will be released in March 2018. ocaml-jupyter requires the following changes:

  • replace lwt.ppx with lwt_ppx
  • migrate logger from lwt.log to logs_lwt

Details: ocsigen/lwt#453

doesn't build on 4.09

I get this error:

# File "compat.cppo.ml", line 32, characters 7-45:
# Error: Unbound module Pparse.ImplementationHooks

Nix/NixOS compatibility; remove installation-time dependency on opam

I am trying to get this to build and work on Nix+NixOS, a "declarative" package manager+operating system with a lot of appeal to the functional programming community.

The existing installation/build process relies on opam to generate and write the Jupyter kernelspec files (kernel.json, kernel.sh). This approach is incompatible with Nix, which manages its own OCaml versions/dependencies and does not use opam. Consequently, when Nix tries to build it like other Dune packages by calling dune build -p jupyter, Dune first tries to generate the kernelspec files by calling config/kernelspec.exe, which tries to call opam, and throws a "command not found" error.

The NixOS-specific fix would be to not generate these kernelspec files at all or at least remove the kernelspec generation script from the default installation step, since NixOS provides its own way of configuring Jupyter to use additional kernels via its jupyter module. But I recognize doing so may make the installation process less convenient for others.

Personally, I think it is best if the installation process is package-manager-neutral, i.e. it doesn't assume what OCaml package manager people are using. Considering that the kernelspec is a Jupyter configuration and is not in any way an actual dependency of the OCaml Jupyter kernel program itself, it makes sense that one should be able to just build the OCaml Jupyter kernel without needing to generate the kernelspec first (NixOS users especially don't need the kernelspec to be generated at all). Following this reasoning, my suggestion is this:

  • Separate the kernel.{json,sh} generation from the Dune installation process. Instead, make kernelspec.ml a separate public executable (named something along the lines of ocaml-jupyter-genspec) that may rely on opam if it needs to and generates the kernelspec files as a convenience tool only for those who want it.
  • Add instructions in the README, telling users to either manually create the kernelspec files following some example or, for opam users, generate it using ocaml-jupyter-genspec.

I believe this is a reasonable compromise: the convenience of auto-generating the kernelspec files remains, but non-opam users won't need to install opam just to build the standalone kernel (opam is only needed for the kernelspec generation), and for opam users there are only 1-2 extra commands to run during installation.

What do you think about this?

error with `Jupyter_comm.Stdin.read_line`

let s = Jupyter_comm.Stdin.read_line ""

The input widget does pop out, but immediately after that:

Exception: End_of_file.
Raised at file "stdlib.ml", line 441, characters 20-31
Called from file "stdlib.ml", line 456, characters 28-39
Called from file "toplevel/toploop.ml", line 180, characters 17-56

printing to stdout and stderr

in an ocaml-jupyter console in the terminal when i try
print_int 8998;;
i get no output except for the return value which is (). similarly, Format.(fprintf std_formatter "sdf") gives no visible output.
it seems that these output channels are swallowed by jupyter somehow?

can't install Jupyter

Hi when I try to install Jupiter with "opal install Jupyter" I have the following message
The following dependencies couldn't be met:

  • jupyter → jbuilder < 1.0+beta18 → ocaml < 4.08.0
    base of this switch (use `--unlock-base' to force)
  • jupyter → lwt < 4.0.0 → ocaml < 4.08.0
    base of this switch (use `--unlock-base' to force)
  • jupyter → ppx_deriving_yojson >= 3.0 → ppx_tools → ocaml < 4.08
    base of this switch (use `--unlock-base' to force)
  • jupyter → ppx_deriving_yojson >= 3.0 → ppx_deriving < 4.3 → ocaml < 4.06.0
    base of this switch (use `--unlock-base' to force)
  • jupyter → ppx_deriving_yojson >= 3.0 → ppx_deriving < 4.3 → ppx_tools >=
    4.02.3 → ocaml < 4.08
    base of this switch (use `--unlock-base' to force)
  • jupyter → ppx_deriving_yojson >= 3.0 → ocaml < 4.05.0
    base of this switch (use `--unlock-base' to force)

No solution found, exiting

It seems that the ocaml version is the problem. Could you please try to fix it ? Thanks

ocaml-jupyter-kernel failing after installation of dev version

Hi again,
I tried installing the dev version from GitHub, with $ opam pin add jupyter https://github.com/akabe/ocaml-jupyter.git.
It seems to work, then I can install the kernel with sudo jupyter kernelspec install --name ocaml-jupyter /home/lilian/.opam/4.04.2/share/ocaml-jupyter but the binary ocaml-jupyter-kernel now fails with this (very explicit) error message:

Fatal error: exception Failure("No such file or director: ")
Raised at file "pervasives.ml", line 32, characters 22-33
Called from file "lib/kernel/JupyterKernelConnectionInfo.ml", line 44, characters 7-54
Called from file "src/JupyterMain.ml", line 57, characters 18-71

As the message does not say anything useful, I have no idea what the issue could be.

Thanks in advance, I really want to try your project and use it over iocaml, but keep failing to install it...

Installation failed on macOS High Sierra

I tried to install the kernel but I did not succeed, due to 2 compilation errors on archimedes.0.4.18 and conf-gmp.1

I paste here the error messages I got :

  1. archimedes
#=== ERROR while installing archimedes.0.4.18 =================================#
# opam-version 1.2.2
# os           darwin
# command      ocaml setup.ml -build
# path         /Users/ferdydurke/.opam/system/build/archimedes.0.4.18
# compiler     system (4.06.1)
# exit-code    1
# env-file     /Users/ferdydurke/.opam/system/build/archimedes.0.4.18/archimedes-19300-ef0aa7.env
# stdout-file  /Users/ferdydurke/.opam/system/build/archimedes.0.4.18/archimedes-19300-ef0aa7.out
# stderr-file  /Users/ferdydurke/.opam/system/build/archimedes.0.4.18/archimedes-19300-ef0aa7.err
### stdout ###
# [...]
# /Users/ferdydurke/.opam/system/bin/ocamlfind ocamlopt -a -I src src/archimedes.cmx -o src/archimedes.cmxa
# /Users/ferdydurke/.opam/system/bin/ocamlfind ocamlopt -shared -I src src/archimedes.cmxa src/archimedes.cmx -o src/archimedes.cmxs
# /Users/ferdydurke/.opam/system/bin/ocamlfind ocamldep -package bigarray -package cairo2 -package camlp4 -package dynlink -package graphics -modules src/archimedes_graphics.ml > src/archimedes_graphics.ml.depends
# /Users/ferdydurke/.opam/system/bin/ocamlfind ocamlc -c -g -annot -bin-annot -I src -I src -I +compiler-libs -package bigarray -package cairo2 -package camlp4 -package dynlink -package graphics -I src -o src/archimedes_graphics.cmo src/archimedes_graphics.ml
# + /Users/ferdydurke/.opam/system/bin/ocamlfind ocamlc -c -g -annot -bin-annot -I src -I src -I +compiler-libs -package bigarray -package cairo2 -package camlp4 -package dynlink -package graphics -I src -o src/archimedes_graphics.cmo src/archimedes_graphics.ml
# findlib: [WARNING] Interface path.cmi occurs in several directories: /usr/local/lib/ocaml/compiler-libs, src
# findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /usr/local/lib/ocaml/compiler-libs, /usr/local/lib/ocaml
# File "src/archimedes_graphics.ml", line 97, characters 6-24:
# Error: Unbound module Graphics
# Command exited with code 2.
### stderr ###
# File "setup.ml", line 7667, characters 15-32:
# Warning 3: deprecated: String.capitalize
# Use String.capitalize_ascii instead.
# File "./src/public_interface.ml", line 25, characters 30-46:
# Warning 3: deprecated: String.lowercase
# Use String.lowercase_ascii instead.
# W: Cannot find source file matching module 'archimedes_internals' in library archimedes_internals
# E: Failure("Command ''/Users/ferdydurke/.opam/system/bin/ocamlbuild' src/archimedes_internals.cma src/archimedes_internals.cmxa src/archimedes_internals.a src/archimedes_internals.cmxs src/archimedes.cma src/archimedes.cmxa src/archimedes.a src/archimedes.cmxs src/archimedes_graphics.cma src/archimedes_graphics.cmxa src/archimedes_graphics.a src/archimedes_graphics.cmxs src/archimedes_cairo.cma src/archimedes_cairo.cmxa src/archimedes_cairo.a src/archimedes_cairo.cmxs src/archimedes_toploop.cma src/archimedes_toploop.cmxa src/archimedes_toploop.a src/archimedes_toploop.cmxs -tag debug' terminated with error code 10")
  1. conf-gmp
#=== ERROR while installing conf-gmp.1 ========================================#
# opam-version 1.2.2
# os           darwin
# command      sh -exc cc -c $CFLAGS -I/opt/local/include -I/usr/local/include test.c
# path         /Users/ferdydurke/.opam/system/build/conf-gmp.1
# compiler     system (4.06.1)
# exit-code    1
# env-file     /Users/ferdydurke/.opam/system/build/conf-gmp.1/conf-gmp-19300-629056.env
# stdout-file  /Users/ferdydurke/.opam/system/build/conf-gmp.1/conf-gmp-19300-629056.out
# stderr-file  /Users/ferdydurke/.opam/system/build/conf-gmp.1/conf-gmp-19300-629056.err
### stderr ###
# + cc -c -I/opt/local/include -I/usr/local/include test.c
# test.c:1:10: fatal error: 'gmp.h' file not found
# #include <gmp.h>
#          ^~~~~~~
# 1 error generated.

Any idea what I could do ?
My configuration is up-to-date, as it seems : Python 3.6.3, XCode 9.2, jupyter 4.3.0...

Using the ocaml kernel on colab

Hi, first thanks a lot for all the hard work on this ocaml kernel - this is a very thing to have.

I just wrote a small colab notebook that lets you install this kernel on free colab instances. Once the first cell of this notebook has run, you can run ocaml notebooks othe same colab instance (by default it will use a cpu instance but I was even able to get it to run on a gpu instance and to use ocaml-torch to train an ocaml model on the gpu).

The notebook can be seen here.

Maybe this would be useful to link to from your repo ? I'm not sure what the easiest way would be to integrate this, perhaps the notebook could be added to your repo and we can have some colab link to it as demonstrated here. Happy to make a PR for this if you think it's worth it - or to go another way if you have some thoughts.

last step failed jupyter kernelspec install --name ocaml-jupyter "$(opam config var share)/jupyter"

error:

(base) brandomiranda~ $ jupyter kernelspec install --name ocaml-jupyter "$(opam config var share)/jupyter"
Traceback (most recent call last):
  File "/Users/brandomiranda/anaconda3/bin/jupyter-kernelspec", line 10, in <module>
    sys.exit(KernelSpecApp.launch_instance())
  File "/Users/brandomiranda/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/Users/brandomiranda/anaconda3/lib/python3.7/site-packages/jupyter_client/kernelspecapp.py", line 273, in start
    return self.subapp.start()
  File "/Users/brandomiranda/anaconda3/lib/python3.7/site-packages/jupyter_client/kernelspecapp.py", line 143, in start
    replace=self.replace,
  File "/Users/brandomiranda/anaconda3/lib/python3.7/site-packages/jupyter_client/kernelspec.py", line 346, in install_kernel_spec
    shutil.copytree(source_dir, destination)
  File "/Users/brandomiranda/anaconda3/lib/python3.7/shutil.py", line 315, in copytree
    names = os.listdir(src)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/brandomiranda/.opam/4.06.0/share/jupyter'

Wait to load the kernel `Fatal error: cannot load shared library dlllwt_unix_stubs`

Hi I have installed this kernel, but not able to use that.
Following is appeared, when I want to use the ocaml kernel.
I do try with the default python2 and 3's kernel, they are working!

~$ jupyter notebook
[I 15:29:36.709 NotebookApp] The port 8888 is already in use, trying another port.
[I 15:29:36.710 NotebookApp] The port 8889 is already in use, trying another port.
[I 15:29:36.718 NotebookApp] Serving notebooks from local directory: /home/jigao
[I 15:29:36.718 NotebookApp] The Jupyter Notebook is running at:
[I 15:29:36.718 NotebookApp] http://localhost:8890/?token=aa5f3a3bd8d80c6cdd56359cb162d632267a08c904d6325c
[I 15:29:36.719 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:29:36.719 NotebookApp] 
    
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8890/?token=aa5f3a3bd8d80c6cdd56359cb162d632267a08c904d6325c
[I 15:29:37.860 NotebookApp] Accepting one-time-token-authenticated connection from 127.0.0.1
Created new window in existing browser session.
[I 15:29:47.811 NotebookApp] Creating new notebook in /Desktop
[I 15:29:49.973 NotebookApp] Kernel started: c425e9d6-e07c-4d48-908d-a8026b869e81
/home/jigao/.opam/4.06.1/share/jupyter/kernel.sh: 1: set: Illegal option -g
[I 15:29:52.968 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
/home/jigao/.opam/4.06.1/share/jupyter/kernel.sh: 1: set: Illegal option -g
[I 15:29:55.976 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
/home/jigao/.opam/4.06.1/share/jupyter/kernel.sh: 1: set: Illegal option -g
[I 15:29:58.985 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
/home/jigao/.opam/4.06.1/share/jupyter/kernel.sh: 1: set: Illegal option -g
[I 15:30:02.026 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
/home/jigao/.opam/4.06.1/share/jupyter/kernel.sh: 1: set: Illegal option -g
[W 15:30:05.085 NotebookApp] KernelRestarter: restart failed
[W 15:30:05.085 NotebookApp] Kernel c425e9d6-e07c-4d48-908d-a8026b869e81 died, removing from map.
[W 15:30:50.237 NotebookApp] Timeout waiting for kernel_info reply from c425e9d6-e07c-4d48-908d-a8026b869e81
[E 15:30:50.242 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: c425e9d6-e07c-4d48-908d-a8026b869e81)

I have a chrome Version 69.0.3497.100 (Official Build) (64-bit).
On a ubuntu Release: 18.04
With jupyter notebook --version 5.7.0

I have read #101, but I think no helpful for me. And there is not detailed documented how to solve such kind of problem.
Thanks for all kinds of hints!

Edit: sorry for reopening this issue. But I do have the newest ocaml jupyter kernel. Maybe this problem lays on other place.

 ~> opam install "jupyter>=2.3.4"
[NOTE] Package jupyter is already installed (current version is 2.4.0).

`inspect_request` schema is wrong

Jul 22 00:57:24.855 debug [ocaml-jupyer]: RECV: HMAC=75a393647db298994ab7a9484502fbdc342937b766d27fa9e784f951e572b92e; header={"session":"240E8E67BD8047D28C7CDC228606EDF7","msg_id":"75F021E6A19E400EB9F1BD125A55174B","msg_type":"inspect_request","version":"5.0","username":"username"}; parent={}; content={"detail_level":0,"cursor_pos":137,"code":"let surface = Cairo.Image.create Cairo.Image.ARGB32 ~width:800 ~height:400 in\nlet ctx = Cairo.create surface in\n  Cairo.arc ctx ~x ~y ~r ~a1:0.0 ~a2:pi2 ;\n  Cairo.fill ctx ;\n  Cairo.PNG.write_to_stream ~output:(Caml.output_string Iocaml.mime) surface  ;\n  Iocaml.send_clear ~context () ;\n  Iocaml.send_mime ~context ~base64:true \"image/png\"\n\noutput_string JupyterNotebook.cellout \"<b>Hello, World</b>\" ;\nJupyterNotebook.display_cell ~ctx \"text/html\""}; metadata={}
Error: Context not closed before finalization
Fatal error: exception Yojson.Json_error("JupyterShellMessage.inspect_request.cursor_pos")
Raised at file "src/core/lwt.ml", line 805, characters 16-23
Called from file "src/unix/lwt_main.ml", line 34, characters 8-18
Called from file "src/JupyterMain.ml", line 61, characters 6-120
Re-raised at file "src/JupyterMain.ml", line 37, characters 4-64
Called from file "src/JupyterMain.ml", line 69, characters 2-9

macos requires zeromq

ocaml install Jupyter produces errors, finishing with:

The packages you requested declare the following system dependencies. Please make sure they are installed before retrying:
zeromq

caml 4.08.1
macOS 0.15.3 Beta
home-brew 2.2.3

fixed by brew install zeromq before Ocaml install Jupiter

Rather obvious fix, then it works fine.

Thanks - great project!

Magic

Hello,
first, thank you for developing this project which is very useful!

With the Python kernel, there are "magic" commands starting with the % sign (for more info, run %magic in a Python kernel).
They have a nice features like %%html to render the cell as a block of HTML, %%latex to render the cell as a block of latex, or %%svg to render the cell as an SVG literal.

Would it be simple to add such functionalities? (I can contribute if needed).

Best,
Anthony

Installation with opam switch

Hi,
I installed the 4.10.0 version of OCaml by doing

opam switch create 4.10.0

Then I installed jupyter:

opam install jupyter

At the end of the installation, I got the following message:

<><> jupyter.2.7.0 installed successfully <><><><><><><><><><><><><><><><><><><>
=> Please run for registration of ocaml-jupyter kernel:
=>
=> $ ocaml-jupyter-opam-genspec
=> $ jupyter kernelspec install --name ocaml-jupyter \
=> /home/scemama/qp2/external/opam/4.10.0/share/jupyter

but the directory /home/scemama/qp2/external/opam/4.10.0/share/jupyter does not exist so the command fails. However, there is a directory named /home/scemama/qp2/external/opam/default/share/jupyter for which the installation works. So there is a little bug in the printed message.

best,
Anthony

[archimedes] Cairo not available for ocaml >4.06

Trying to install jupyter-archimedes on Ocaml 4.07.1, getting a compatibility error because of cairo. Should it be switched to cairo2, which seems to install fine?

$ opam install jupyter-archimedes
The following actions will be performed:
  ∗ install jupyter-archimedes 2.3.2

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[jupyter-archimedes.2.3.2] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of jupyter-archimedes failed at "/home/mbesancon/.opam/4.07.1/bin/dune build -p jupyter-archimedes -j 4".

#=== ERROR while compiling jupyter-archimedes.2.3.2 ===========================#
# context     2.0.4 | linux/x86_64 | ocaml-base-compiler.4.07.1 | https://opam.ocaml.org/#f38e11b0
# path        ~/.opam/4.07.1/.opam-switch/build/jupyter-archimedes.2.3.2
# command     ~/.opam/4.07.1/bin/dune build -p jupyter-archimedes -j 4
# exit-code   1
# env-file    ~/.opam/log/jupyter-archimedes-26878-05296d.env
# output-file ~/.opam/log/jupyter-archimedes-26878-05296d.out
### output ###
# File "jupyter-archimedes/src/dune", line 10, characters 14-30:
# 10 |               archimedes.cairo))
#                    ^^^^^^^^^^^^^^^^
# Error: Library "archimedes.cairo" in /home/mbesancon/.opam/4.07.1/lib/archimedes is hidden (unsatisfied 'exist_if').
# Hint: try: dune external-lib-deps --missing -j 4 -p jupyter-archimedes @@default



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build jupyter-archimedes 2.3.2
└─ 
╶─ No changes have been performed

Fatal error: x unbound at toplevel

I just installed jupyter in a new opam switch in a macOS with opam/ocaml installed from Homebrew.

vf new learning
pip install jupyter
opam switch learning --alias-of 4.06.0
opam install jupyter
jupyter kernelspec install --sys-prefix --name ocaml-jupyter /thecreateddirectory
eval (opam config env)
jupyter notebook

Note, vf is just a wrapper around virtualenv

This is my ocamlinit configuration:

(* Added by OPAM. *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

#use "topfind" ;;
#thread ;;
#require "core.top";;
#require "core.syntax" ;;

open Core

When creating a new notebook with the OCaml kernel, while I evaluate new expressions everything works fine:

7 + 1 ;;
- : int = 8

But as soon as I try to bound to a new variable, an exception occurs:

let x = 200;
>> Fatal error: x unbound at toplevel
Uncaught exception:
  
  Misc.Fatal_error

Raised at file "utils/misc.ml", line 21, characters 60-71
Called from file "toplevel/toploop.ml", line 206, characters 36-75
Called from file "typing/printtyp.ml", line 1319, characters 29-45
Called from file "list.ml", line 82, characters 20-23
Called from file "typing/printtyp.ml", line 1319, characters 6-53
Called from file "toplevel/toploop.ml", line 283, characters 40-60
Called from file "utils/misc.ml", line 28, characters 20-27
Re-raised at file "utils/misc.ml", line 28, characters 56-57
Called from file "utils/misc.ml", line 40, characters 10-14
Re-raised at file "utils/misc.ml", line 42, characters 44-45
Called from file "typing/env.ml", line 580, characters 10-104
Called from file "toplevel/toploop.ml", line 265, characters 16-829
Re-raised at file "toplevel/toploop.ml", line 308, characters 38-39
Called from file "toplevel/toploop.ml", line 350, characters 6-42
Re-raised at file "toplevel/toploop.ml", line 353, characters 10-13
Called from file "jupyter/src/repl/evaluation.ml", line 88, characters 14-53
Called from file "jupyter/src/repl/evaluation.ml", line 98, characters 12-40
Called from file "jupyter/src/repl/evaluation.ml", line 111, characters 4-56
Re-raised at file "parsing/location.ml", line 465, characters 22-25
Re-raised at file "parsing/location.ml", line 465, characters 22-25
Re-raised at file "parsing/location.ml", line 465, characters 22-25
Re-raised at file "parsing/location.ml", line 465, characters 22-25
Re-raised at file "parsing/location.ml", line 465, characters 22-25
Re-raised at file "parsing/location.ml", line 465, characters 22-25
Called from file "jupyter/src/repl/error.ml", line 138, characters 2-29
Called from file "jupyter/src/repl/evaluation.ml", line 117, characters 14-62
Called from file "jupyter/src/repl/process.ml", line 66, characters 8-80
Called from file "jupyter/bin/jupyter_main.ml", line 47, characters 4-168
In [ ]:

x

Unable to specify different notebooks directory when using Docker

First of all: Sorry, I am quite new to Docker and the solution probably is trivial.
Both given commands do not provide the option to use a diferent directory for my jupyter notebooks.

How can I launch the ocaml notebook in my home directory? The "-v" flag does not work for me.
(I am using Mac OSX 10.14.1)

Passing additional parameters to OCaml

Greetings,

I am just starting to look into using Jupyter and your kernel instead of Emacs+Tuareg for my introductory course.

I am using Arthur Charguéraud's kernel fork (based on 4.02.2) which supports better error messages.

I was able to install your kernel under the appropriate opam switch but I have to pass option -easy-type-errors to ocaml in order to activate the better messages.

How can I do this ? Adding the option to argv in the json does not work as the kernel does not recognise the option.

Can't load kernel

Hi,
I'm trying to install ocaml-jupyter for jupyterhub.

My installation seems to work with python kernel.
The installation of ocaml-jupyter was successfull.

But when i try to open a new file with Ocaml kernel, i get that error.
I think it's a permission problem, but i don't know which file/folder is concerned by the error.

Maybe you could help me.

Yannick

in the Jupyterhub new file when i click on Kernel Error :

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/tornado/web.py", line 1699, in _execute
result = await result
File "/usr/local/lib/python3.5/asyncio/futures.py", line 383, in iter
return self.result() # May raise too.
File "/usr/local/lib/python3.5/asyncio/futures.py", line 294, in result
raise self._exception
File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 736, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/usr/local/lib/python3.5/site-packages/notebook/services/sessions/handlers.py", line 73, in post
type=mtype))
File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 729, in run
value = future.result()
File "/usr/local/lib/python3.5/asyncio/futures.py", line 294, in result
raise self._exception
File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 736, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/usr/local/lib/python3.5/site-packages/notebook/services/sessions/sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 729, in run
value = future.result()
File "/usr/local/lib/python3.5/asyncio/futures.py", line 294, in result
raise self._exception
File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 736, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/usr/local/lib/python3.5/site-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 729, in run
value = future.result()
File "/usr/local/lib/python3.5/asyncio/futures.py", line 294, in result
raise self._exception
File "/usr/local/lib/python3.5/site-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.5/site-packages/notebook/services/kernels/kernelmanager.py", line 160, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/usr/local/lib/python3.5/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/usr/local/lib/python3.5/site-packages/jupyter_client/manager.py", line 259, in start_kernel
**kw)
File "/usr/local/lib/python3.5/site-packages/jupyter_client/manager.py", line 204, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "/usr/local/lib/python3.5/site-packages/jupyter_client/launcher.py", line 138, in launch_kernel
proc = Popen(cmd, **kwargs)
File "/usr/local/lib/python3.5/subprocess.py", line 676, in init
restore_signals, start_new_session)
File "/usr/local/lib/python3.5/subprocess.py", line 1289, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

in the Jupyterhub log I have this more :

E 2019-05-05 00:45:57.293 SingleUserNotebookApp launcher:149] Failed to run command:
['/root/.opam/4.04.1/bin/ocaml-jupyter-kernel', '--init', '/root/.ocamlinit', '--merlin', '/root/.opam/4.04.1/bin/ocamlmerlin', '--connection-file', '/home/???/.local/share/jupyter/runtime/kernel-4da55fd3-6194-47fe-9bce-8dd4f894dcdc.json']
PATH='/root/.opam/4.04.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
with kwargs:
{'start_new_session': True, 'stdin': -1, 'stderr': None, 'cwd': '/home/???', 'stdout': None}

[E 2019-05-05 00:45:57.294 SingleUserNotebookApp web:1788] Uncaught exception POST /user/???/api/sessions (92.93.242.71)
HTTPServerRequest(protocol='http', host='jhub.???.fr', method='POST', uri='/user/???/api/sessions', version='HTTP/1.1', remote_ip='92.93.242.71')

Owl support

It would be great to make this fully compatible with Owl. This would give a full-fledged scientific notebook environment in ocaml.

I have tried with a patched master and everything seems to work, the only missing bits are:

  • a backend for plplot (that can use cairo as well) or its higher level interface used in owl
  • support for owl multiline output (or fix for it in owl, I am not sure what's better/easier). For example a 4 by 4 matrix is shown as
    # Mat.uniform 4 4;;
                                                                                                                                                                                                                             
    C0       C1       C2       C3                                                                                                                                                                              
    R0 0.873982 0.799467 0.545207 0.160527
    R1 0.676436 0.590859 0.744383  0.99189
    R2 0.527598  0.68333 0.174403 0.330034
    R3   0.1083 0.646665 0.529998 0.727835
    - : Mat.mat =
    
    but in ocaml-jupyter I see only - : Mat.mat =

Ping also @ryanrhymes that could be interested

Add some utilities

  • JupyterNotebook.display_file
  • JupyterNotebook.formatter, .printf, .display_formatter

Fail to install with opam

Apparently, the installation script tries to install the kernel to /usr/share/jupyter/kernels/, which would require root rights, but I am unable to either launch opam install jupter with the good options or with sudo.

The error is:

[Errno 13] Permission denied: '/usr/local/share/jupyter/kernels/ocaml-jupyter-4.04.2'
Perhaps you want to install with `sudo` or `--user`?
E: Failure("Command './kernelspec.sh install true /home/lilian/.opam/4.04.2/share/ocaml-jupyter' terminated with error code 1")

I tried to manually hack the kernelspec.sh script to force using sudo jupyter ... and reinstalling from local archive (manually modified), but this is not working.

Any insights? Any easy way of fixing that?
Thanks!

PS: it could help to also provide instructions on how to compile and install from the git repository.

Syntax highlight in lists

I have no idea if this is a bug related to the Jupyter kernel or CodeMirror (Jupyter JS syntax highlight lib).

In a list, the first element is never highlighted, or every other element is highlighted, for example:

[2 ; 4; 5]

Highlights 2 and 3, but not 1 (see attachment)

screen shot 2017-12-06 at 13 27 11

This only happens with numbers, not other type.

This behaviour happens in the akabe/iocaml:latest docker image

Magic commands

Python and sage kernels support the %load magic command to load up some util code into a single cell.
It'd be nice to have this here without having to install glue code into the default opam path.

Graphics Implementation

Hi,
Is there an implementation of the Graphics module in jupyter-ocaml?
When I try to open a graphic:

#load "graphics.cma";;
open_graph "";

I'm getting this error:

Exception: Graphics.Graphic_failure "Cannot open display ".
Raised by primitive operation at unknown location
Called from file "toplevel/toploop.ml", line 180, characters 17-56

Thank you in advance!

Automatic handling of Lwt.t and Async.t

Hello,
utop includes some magic so that top level expressions of types 'a Lwt.t or 'a Async.t are transformed into blocking calls that return the underlying 'a. Maybe it would be nice to support the same kind of thing in the jupyter kernel ?
For what it's worth by copying and pasting lines 420-580 of uTop_main.ml, I was able to get this to work with very small changes. I'm happy to make a PR out of it if you think that's interesting.

Weird display issue for val in stdout with _ (_ not displayed)

Hi! 🎉 Merry new year!

Here is an example of a weird display issue:
bug_display_out_value_with_underscore_in_its_name
(The variable ex1_1 but displayed ex1 1. On Firefox 57, Ubuntu 17.10)

It's a bug probably coming from the style in outputarea.less:96.
I can fix it by forcing a padding-bottom: 1px; rule for div.output_area pre:
bug_display_out_value_with_underscore_in_its_name2

I will submit the PR to fix this.

How to use this kernel from the jupyter-console command line?

Is it possible to use this kernel from the jupyter-console command line repl?

I think it should be, if the implementation of the kernel is sufficiently independent from the web jupyter notebook, but when I tried this jupyter-console --kernel="ocaml-jupyter", I encounter this issue:

$ jupyter-console --kernel='ocaml-jupyter'
Error: Context not closed before finalization
Error: Socket not closed before finalization
Error: Socket not closed before finalization
Error: Socket not closed before finalization
Error: Socket not closed before finalization
Error: Socket not closed before finalization
Fatal error: exception Yojson.Json_error("JupyterShellMessage.request")
Raised at file "src/core/lwt.ml", line 805, characters 16-23
Called from file "src/unix/lwt_main.ml", line 34, characters 8-18
Called from file "src/JupyterMain.ml", line 65, characters 6-122
Re-raised at file "src/JupyterMain.ml", line 37, characters 4-64
Called from file "src/JupyterMain.ml", line 73, characters 2-9
Jupyter console 5.2.0

None


In [1]: /usr/local/lib/python2.7/dist-packages/jupyter_console/ptshell.py:617: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
  warn('The kernel did not respond to an is_complete_request. '
In [1]: 

and the prompt seems to not be connected to any kernel backend.

(note that this is not so important, utop is already a great repl for OCaml, I am mainly curious!)

qtconsole crashes on start

i tried jupyter qtconsole --kernel=ocaml-jupyter with a kernel that works in the regular console. it fails with:

    raise TraitError(e)
traitlets.traitlets.TraitError: The 'kernel_banner' trait of a RichJupyterWidget instance must be a unicode string, but a value of None <class 'NoneType'> was specified.

i noticed that when i start the regular jupyter console, None is echoed on startup which might have something to do with that.

kernel keeps busy and not usable in jupyter-lab

I've tried ocaml-jupyter version 2.0.0 with
jupyter 4.3.0
python 3.6.3
ipython 6.2.1
jupyterlab 0.29.2

and when I start jupyter with jupyter notebook everything works, while via jupyterlab, it hangs on kernel start and I can not execute any command (when hit "Shift+Enter" it shows In [*], and no message sent in session websocket.

according to kernel status description

Changed in version 5.0: Busy and idle messages should be sent before/after handling every request, not just execution.

I think this also applies to kernel_info_request.

Switch to jbuilder from oasis

Hi!

You have a new and very exciting project here. But since it's so new, I'm wondering why you decided to use oasis over jbuilder. Jbuilder has many benefits over oasis (like far faster builds for example), so I'm wondering if there are any deficiencies to it in your view or you simply haven't gotten around to it.

Output from multiple cells are not displayed correctly

Hi again,
Everything seems to work fine, but I found a weird behavior, possibly a bug.

When I hit "Run all cells", or "All above" or "All below", or select multiple cells and execute them, only the last one shows the output from all the executed cells.
I think this is a bug, could you try to reproduce it? It seems to occur for long running cells (more than 1 seconds).

See this example, the first 2 cells are correctly executed, the next 2 are executed while being jointly selected, and the output are merged and online displayed for the 2nd cell:
gifrecord_2017-09-13_202326

It shouldn't be too hard to fix, the kernel server is probably keeping a buffer of its output (received by the notebook) and the buffer is not flushed as often as it should be...

Running different OCaml versions

I now have a jupyter kernel for OCaml 4.02.2 and another one for OCaml 4.07.0. They both appear in the Jupyter menu but I seem to be able to run only one of them, depending on which opam switch was active in the environment that launched the jupyter server.

From the error messages in the console, I think this is because of inadequate LDPATH.

This in spite of both kernel JSONs specifying the absolute path to the relevant ocaml-jupyter-kernel and the shebang in them also specifying the absolute path to the relevant ocamlrun.

But the environment is not set.

This could be solved by outputting opam env as an env dict in the kernel json. But this might be problematic for the PATH, be cause we want to add the relevant opam path, not replace the whole PATH variable and we cannot know at the time of the generation of kernel.json what will be the PATH variable at execution time.

Another way would be to have in the ocaml-jupyter-kernel shebang a small shell script that would set the environment with opam env --switch=XXX and then become ocamlrun.

the merlin server requires .merlin path to be absolute

In the current setting of ocaml-jupyter, the .merlin file is completely ignored. This is because the server mode of merlin requires an absolute path to the .merlin file. For example, try:

cd ~/test   # assuming that there's a valid .merlin in there
echo " " | ocamlmerlin single check-configuration -dot-merlin .merlin   # this works
echo " " | ocamlmerlin server check-configuration -dot-merlin .merlin # this doesn't
echo " " | ocamlmerlin server check-configuration -dot-merlin ~/test/.merlin # this works again

I guess there must be a good reason for that. Not sure what the best fix is, at the moment I'm simply adding a "--dot-merlin", "~/test/.merlin" pair in my /usr/local/share/jupyter/kernels/ocaml-jupyter/kernel.json, but this is bad... Alternatively, is there a way of providing a project-specific kernel.json file?

Reading a cell as an OCaml string

I want to write an OCaml function that will read the contents of a given cell and return them as an OCaml string.
This is probably not an issue with a library, but I am wondering whether you think this is possible to do through the current API and if you can point me at the right direction.

Thank you and happy holidays!

Unable to install with a non-standard opam root

When trying to install with a custom opam root (/opam, owned by the current user), I'm getting the following error:

kernelspec config/kernel.{json,sh} (exit 2)
(cd _build/default/config && ./kernelspec.exe)
[ERROR] /opam exists, but does not appear to be a valid opam root. Please remove it and use
        `opam init', or specify a different `--root' argument
Fatal error: exception Failure("opam config var switch")

Running opam config var switch as the current user returns the current switch without any issue (and I don't have any problem when installing other packages).

console use

I have been exploring using ocaml-jupyter from the jupyter console.
(See https://discuss.ocaml.org/t/jupyter-a-better-utop/2633)

It's working pretty well! However a few things could be improved for console use.

  • directives. is there a way to get the utop directives to work? ls, cd, pwd, things like that.
  • Merlin completion works out of the box but not for ocaml directives such as #require and on package names
  • Merlin inspection does not seem to work. is this a problem of the console not recognizing shift+tab?

Instalation Problem

Hey, when i try to run the command opam install iocaml i get this error
The following dependencies couldn't be met:
- iocaml → iocamljs-kernel >= 0.4.6 → js_of_ocaml < 3.0 → ocaml < 4.05.0 base of this switch (use --unlock-base to force)
- iocaml → ocaml < 4.02.0 base of this switch (use --unlock-base' to force)

should not depend on "jupyter" location to determine whether use suedo

e.g. in mac with homebrew, jupyter locates at /usr/local/bin/jupyter while you do not require sudo permission to write to /usr/local (and should not)

I think that instead of install manage kernel via opam, I prefer just write a warning log like

please run 'jupyter kernelspec install [--user] "$datadir"' to install the kernel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.