How to install jupyter kernel for Matlab#
Updated on 03 July 2025
Fixed broken link in Matlab release section.
In this tutorial, we will describe i) the steps to create a kernel for Matlab and ii) get the matlab_kernel
working in Jupyterhub on Levante.
Prerequisites#
conda environment with python 3.9
matlab_kernel package
matlab python engine (from the matlab module)
python bindings
Note
For some reasons, there will be no centralized kernel for Levante in jupyterhub.
Matlab release#
Check this table first when you create the conda environment.
To check the available Matlab modules on Levante:
module av matlab
which (currently) returns:
matlab/R2021b-gcc-11.2.0
matlab/R2024b-gcc-13.3.0
matlab/R2021b6-gcc-11.2.0
Instructions#
Please follow these steps to install and enable the matlab_kernel
in
Jupyterhub.
1. Conda env#
Create a conda environment to install matlab_kernel package.
module load python3
conda create -n matlab -c conda-forge python=3.9
source activate matlab
2. Matlab Kernel#
In the conda env:
python -m pip install matlab_kernel
python -m matlab_kernel install --user
A kernel specification kernel.json is now available under .local/share/jupyter/kernels/matlab.
You need to edit that file and change the path to python, it should point to the python from the conda environment.
{"argv": ["/home/../../.conda/envs/matlab/bin/python", "-m",
3. Python engine and bindings#
We will be using Matlab R2021b.
(matlab) [k@l40106 ~]$ cd /sw/spack-levante/matlab-R2021b-klsayl/extern/engines/python/
(matlab) [k@l40106 python]$ python setup.py build -b $HOME
running build
running build_py
(matlab) [k@l40106 python]$
This will create a directory lib/matlab
in your home directory.
4. Move/copy the directory to the conda env#
Now, you move/copy the lib/matlab
into
path/to/your/conda_env/lib/python3.9/site-packages/matlab
(matlab) [k@l40106 python]$ cd
(matlab) [k@l40106 ~]$ mv lib/matlab/ .conda/envs/matlab/lib/python3.9/site-packages/matlab
Note
You can delete the lib/matlab from your HOME directory if everything work!
Updated on 07 July 2025
There is a script that automates the steps above, you can download it here.
Testing#

start jupyterhub session
create a new notebook with
matlab
kerneldisp('hello from MATLAB')
hello from MATLAB
Or try this notebook.
Troubleshooting#
Matlab engine not found
ImportError:
Matlab engine not installed:
See https://www.mathworks.com/help/matlab/matlab-engine-for-python.htm
This means you missed step 2.
SetuptoolsDeprecationWarning: Invalid version: ‘R2021b’
Downgrade setuptools to version 58.2.0
python -m pip install setuptools==58.2.0
OSError: MATLAB Engine for Python supports Python version 2.7, 3.7, 3.8, and 3.9, but your version of Python is 3.10
check the compatibility table and the python version of python venv
References#
[2] https://am111.readthedocs.io/en/latest/jmatlab_install.html