- We assume that you are comfortable with Linux command line. If not, checkout out Ryans’ tutorial for example.
- We also assume that you already have MATLAB installed and working. This tutorial is tested successfully with MATLAB R2017a on Mac/Linux/Windows.
Install the standard Jupyter-Python notebook¶
Jupyter relies on Python, so the first thing is to install Anaconda, a popular distribution of scientific Python. Experienced users prefer Miniconda to only install necessary packages, but the standard Anaconda is more convenient for beginners, especially on Windows.
Once you have conda installed, you should test the standard IPython notebook. For example, in the notebook execute
%%python # I am in a MATLAB kernel so need to add the above IPython magic to use the python kernel instead. # You can skip this magic in a standard python kernel print('hello from Python')
hello from Python
(1) Python-side configuration¶
Open the terminal, execute the following command to check your installation of anaconda and python:
which conda pip python
All of them should be inside anaconda’s directory “…/anaconda3/bin”
MATLAB R2017a only interfaces with Python3.5, so we need to create a new virtual environment:
conda create -vv -n jmatlab python=3.5 jupyter
Enter this Python environment. Stay in this environment when executing any terminal commands (pip, python, jupyter) for rest of this tutorial.
source activate jmatlab
Then, install the Matlab kernel for Jupyter.
pip install matlab_kernal python -m matlab_kernel install
Check if the kernel is installed correctly
jupyter kernelspec list
You should see both Python and MATLAB.
(2) MATLAB-side configuration¶
Now we need to expose the MATLAB executable to Jupyter.
Find your MATLAB directory. On Mac it will be like “/Applications/MATLAB_R2017a.app”.
Go to the “extern/engines/python” subdirectory and install the Python engine.
cd “/Applications/MATLAB_R2017a.app/extern/engines/python” python setup.py install
Windows is always tricker when it comes to configuring software, but all you need is basically translating Linux commands into Windows commands.
Commonly used Linux/Mac <-> Windows command mappings are:
e:to change the disk E)
You might also need to set environment variables if commands like “python” and “conda” cannot be recognized. Add the following directories to the PATH variable:
All steps are exactly the same as in the Mac/Linux section. Windows is indeed a litte bit annoying, but it doesn’t prevent Jupyter+MATLAB from working. Please contact me if you have any troubles.