Open farhi opened 5 years ago
A good alternative is to use imatlab which brings a Matlab into Jupiter:
which can probably be made into a Debian package.
Install for Ubuntu 18.04, python 3.6 (from system), matlab R2017a:
import_module("matlabengineforpython3_5")
[2 locations]Installation is done in:
Notes above from:
Works OK in Jupyter.
Matlab Engine R2017a Installation output:
# cd /opt/MATLAB/R2017a/extern/engines/python
# sudo python3.6 setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/matlab
copying dist/matlab/__init__.py -> build/lib/matlab
copying dist/matlab/mlexceptions.py -> build/lib/matlab
copying dist/matlab/mlarray.py -> build/lib/matlab
creating build/lib/matlab/engine
copying dist/matlab/engine/engineerror.py -> build/lib/matlab/engine
copying dist/matlab/engine/__init__.py -> build/lib/matlab/engine
copying dist/matlab/engine/matlabengine.py -> build/lib/matlab/engine
copying dist/matlab/engine/basefuture.py -> build/lib/matlab/engine
copying dist/matlab/engine/matlabfuture.py -> build/lib/matlab/engine
copying dist/matlab/engine/futureresult.py -> build/lib/matlab/engine
copying dist/matlab/engine/enginesession.py -> build/lib/matlab/engine
copying dist/matlab/engine/fevalfuture.py -> build/lib/matlab/engine
creating build/lib/matlab/_internal
copying dist/matlab/_internal/__init__.py -> build/lib/matlab/_internal
copying dist/matlab/_internal/mlarray_utils.py -> build/lib/matlab/_internal
copying dist/matlab/_internal/mlarray_sequence.py -> build/lib/matlab/_internal
running install_lib
creating /usr/local/lib/python3.6/dist-packages/matlab
creating /usr/local/lib/python3.6/dist-packages/matlab/_internal
copying build/lib/matlab/_internal/__init__.py -> /usr/local/lib/python3.6/dist-packages/matlab/_internal
copying build/lib/matlab/_internal/mlarray_utils.py -> /usr/local/lib/python3.6/dist-packages/matlab/_internal
copying build/lib/matlab/_internal/mlarray_sequence.py -> /usr/local/lib/python3.6/dist-packages/matlab/_internal
copying build/lib/matlab/__init__.py -> /usr/local/lib/python3.6/dist-packages/matlab
copying build/lib/matlab/mlexceptions.py -> /usr/local/lib/python3.6/dist-packages/matlab
copying build/lib/matlab/mlarray.py -> /usr/local/lib/python3.6/dist-packages/matlab
creating /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/engineerror.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/__init__.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/matlabengine.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/basefuture.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/_arch.txt -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/matlabfuture.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/futureresult.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/enginesession.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
copying build/lib/matlab/engine/fevalfuture.py -> /usr/local/lib/python3.6/dist-packages/matlab/engine
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/_internal/__init__.py to __init__.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/_internal/mlarray_utils.py to mlarray_utils.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/_internal/mlarray_sequence.py to mlarray_sequence.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/__init__.py to __init__.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/mlexceptions.py to mlexceptions.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/mlarray.py to mlarray.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/engineerror.py to engineerror.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/__init__.py to __init__.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/matlabengine.py to matlabengine.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/basefuture.py to basefuture.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/matlabfuture.py to matlabfuture.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/futureresult.py to futureresult.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/enginesession.py to enginesession.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/matlab/engine/fevalfuture.py to fevalfuture.cpython-36.pyc
running install_egg_info
Writing /usr/local/lib/python3.6/dist-packages/matlabengineforpython-R2017a.egg-info
Test with:
# ipython3
import matlab.engine
eng = matlab.engine.start_matlab()
imatlab installation output [https://github.com/imatlab/imatlab] :
# sudo pip3 install imatlab
Collecting imatlab
Downloading https://files.pythonhosted.org/packages/92/4d/ddd1e0df607266826ab2c3fe6641e3daaa7ca917c906595e362413894fcb/imatlab-0.3-py3-none-any.whl
Requirement already satisfied: widgetsnbextension>=1.0 in /usr/lib/python3/dist-packages (from imatlab)
Requirement already satisfied: nbconvert>=4.2 in /usr/lib/python3/dist-packages (from imatlab)
Requirement already satisfied: plotly>=1.13.0 in /usr/lib/python3/dist-packages (from imatlab)
Requirement already satisfied: ipykernel>=4.1 in /usr/lib/python3/dist-packages (from imatlab)
Requirement already satisfied: matlabengineforpython>=R2016b in /usr/local/lib/python3.6/dist-packages (from imatlab)
Requirement already satisfied: testpath in /usr/lib/python3/dist-packages (from nbconvert>=4.2->imatlab)
Installing collected packages: imatlab
Successfully installed imatlab-0.3
# sudo python3 -mimatlab install
Installed kernelspec imatlab in /usr/local/share/jupyter/kernels/imatlab
Test by starting Jupyter and a Matlab kernel (pop-up 'New' menu, top-right). You can then type e.g.:
will display the static graphics in the Jupyter notebook session.
Configure Jupyter and apache for distant connexion:
This includes a user/passwd login.
Installation of PlotLy (only once to set the credentials):
Setting offline plotting (at every Matlab startup):
Generating plotly figures:
indicates that the configuration file has to allow distant connection in file:
then changes lines:
To add a password, use:
will modify the above configuration to store the password as a hash (encoded).
An other solution is to write a Jupyter Kernel around iFit runtime executable:
seems rather simple to set-up.
The above example does not start the kernel. An example that works properly:
Installation:
# sudo python3 setup.py install
/usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/echo_kernel
copying echo_kernel/__init__.py -> build/lib/echo_kernel
copying echo_kernel/install.py -> build/lib/echo_kernel
copying echo_kernel/kernel.py -> build/lib/echo_kernel
copying echo_kernel/__main__.py -> build/lib/echo_kernel
running install_lib
creating /usr/local/lib/python3.6/dist-packages/echo_kernel
copying build/lib/echo_kernel/__init__.py -> /usr/local/lib/python3.6/dist-packages/echo_kernel
copying build/lib/echo_kernel/install.py -> /usr/local/lib/python3.6/dist-packages/echo_kernel
copying build/lib/echo_kernel/kernel.py -> /usr/local/lib/python3.6/dist-packages/echo_kernel
copying build/lib/echo_kernel/__main__.py -> /usr/local/lib/python3.6/dist-packages/echo_kernel
byte-compiling /usr/local/lib/python3.6/dist-packages/echo_kernel/__init__.py to __init__.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/echo_kernel/install.py to install.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/echo_kernel/kernel.py to kernel.cpython-36.pyc
byte-compiling /usr/local/lib/python3.6/dist-packages/echo_kernel/__main__.py to __main__.cpython-36.pyc
running install_egg_info
Writing /usr/local/lib/python3.6/dist-packages/echo_kernel-1.1.egg-info
# sudo python3 -m echo_kernel.install
Installing Jupyter kernel spec
Locations:
__init.py__
and __main.py__
. The actual kernel is in kernel.py
.Actually, there is also a simple plotter kernel:
which mentions the format of the messaging protocol:
iData and iFunc classes can inherit from multiple sub-classes, e.g.:
Master class:
Sub classes (see https://github.com/McStasMcXtrace/iFit/blob/master/Docs/Methods.html):
Then we assemble
which builds all bits and allow each sub-class to be rather small.