kotlin-jupyter
kotlin-jupyter copied to clipboard
Running the kotlin-jupyter kernel in google colab
This might be more of a question than an issue - I'll have a go anyways;
Did anyone have success running the kotlin-jupyter kernel in google colab?
I tried running this notebook:
- Edited the notebook source in the gist to change its kernelspec to "kotlin"
- Opened the notebook from the gist
- Watched the notebook fail loading the kernel for kotlin which is not installed yet
- Ran the first cell to install it
- Reloaded the notebook to make it connect again, as the kernel is now installed in the instance
Expected outcome: The notebook connects to the new kernel as specified in the kernelspec json in the notebook source, and the following cell with kotlin code can be run.
Actual outcome: The notebook repeatedly tries to connect, fails and crashes.
I previously had success with running clojure in colab in a similar fasion.
Any ideas? Thanks in advance.
Hi! To run Kotlin kernel, Java 11 should be installed on the machine, maybe that's the reason?
Attempted an install using the pip install-jdk package, still no juice
Edit: sudo apt install openjdk-11-jdk
instead of install-jdk renders the same result
The logs are a bit hard to get to as the log window keeps closing every time the runtime attempts a reconnect, but in a flash I saw this.
/usr/bin/python2: No module named run_kotlin_kernel
Any ideas?
Alternatively, you can download kotlin in colab... which is obviously slower (Please note I am a newbie to Kotlin and was going through a Android Kotlin tutorial with exercises when I thought about using a jupyter notebook and colab so I cannot guarantee the soundness of these approaches as alternatives)
Here are three ways:
-
Using %%writefile and function call to compile and run compile_and_run_kotlin_function.ipynb
-
Using custom cell magic which has nasty syntax highlighting thinking that is python cell_magic_with_annoying_python_syntax_errors_for_kotlin.ipynb
-
Using a C program (which was hobbled quickly together from two examples so isn't probably the best C program around) to read text from a cell with %%script cell magic, which then compiles and runs the code. This means there are no annoying syntax highlighting with errors though. Obviously, you can compile the C program, put it on github and then wget or curl the program and hence get more screen space back by getting rid of 2 cells cell_magic_compile_run_kotlin.ipynb Download binary so 2 cells not used. cell_magic_compile_run_kotlin_download_bin.ipynb
I almost got kotlin kernel working in jupyter kernel.
the main reason it don't "just work" is because zmq in java don't support icp protocol which google colab uses.
you can workaround that by using icp proxy like https://gist.github.com/SpencerPark/e2732061ad19c1afa4a33a58cb8f18a9
but even when you have that done(*) then you hit the next snag that colab is jupyter 5.x based and here there is a user_variable
in the json payload that kotlin kernel chokes on. I've opened #440 in hope of getting that fixed.
(*) I have a jbang script that setup various jvm kernels. one can run in colab using the following python snippet:
!pip install jbang
import jbang
jbang.exec("trust add https://github.com/jupyter-java")
jbang.exec("install-kernel@jupyter-java kotlin")
after that you can switch to the kernel with "kotlin ipc" in the name.
it works but stalls/fails due to the kernel failing on #440