Is it possible to run mojo on jupyterlab?

I’m aware of the mojo notebooks and the visual studio code extension that let’s you run mojo as notebooks, but I’m looking to install it on jupyterlab so some of our students can give it a try.

Our students come from many backgrounds so I will need it to be as easy and familiar as possible to run mojo. I’m pretty sure this can be done but I’m not really sure how since my experience with jupyterlab is just using python but, I guess you could run mojo as a kernel somehow?

If anyone has any ideas or resources on how to do this It would be really helpful.

Hi @Dasor! This is pretty easy to do. After installing Magic, any project that includes MAX or Mojo automatically will include the mojo-jupyter package, which includes a Jupyter kernel. We don’t include JupyterLab in our default dependencies, but it’s easy to add. Here’s an example session where I set up JupyterLab with a Mojo kernel:

ubuntu@mdcm-akirchhoff-sdktest:~$ magic init example --format mojoproject
✔ Created /home/ubuntu/example/mojoproject.toml
✔ Added max >=24.5.0,<25
ubuntu@mdcm-akirchhoff-sdktest:~$ cd example
ubuntu@mdcm-akirchhoff-sdktest:~/example$ magic shell
(example) ubuntu@mdcm-akirchhoff-sdktest:~/example$ magic add jupyterlab
✔ Added jupyterlab >=4.3.3,<5
(example) ubuntu@mdcm-akirchhoff-sdktest:~/example$ jupyter lab
[I 2024-12-13 22:52:11.856 ServerApp] jupyter_lsp | extension was successfully linked.
...
[I 2024-12-13 22:52:13.643 ServerApp] Jupyter Server 2.14.2 is running at:
[I 2024-12-13 22:52:13.643 ServerApp] http://localhost:8888/lab?token=4917c09cf781b3b132fe440a96df561aeb5fe2bdad3352f8
[I 2024-12-13 22:52:13.643 ServerApp]     http://127.0.0.1:8888/lab?token=4917c09cf781b3b132fe440a96df561aeb5fe2bdad3352f8
[I 2024-12-13 22:52:13.643 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

If you open the link, you’ll be greeted with an extra option in the launcher:

Just click the “MAX (Conda ENV Mojo kernel)” tile to open a new notebook that uses a Mojo kernel. Here’s an example notebook I made after clicking that tile.

I hope this helps!

6 Likes

It certainly did, I didn’t realize there was a mojo-jupyter package, many thanks!

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.