MATLAB: Python interface to MATLAB Runtime

MATLAB Compiler SDKpython

Hello!
Generating and installing a python library for Windows from MATLAB with the Compiler SDK works well.
In the python main program calls to the library can be well initiated acc. to the description with "import mylib" and "mylib.initialize()".
Generating MATLAB arrays for calling the library functions failes: "import matlab" gives an error "No module named matlab".
I enhanced the Windows path and the environmental variable PYTHONPATH with the MATLAB Runtime path "mcrroot\v95\runtime\win64". No effect.
So every examples from the Pythons User's guide (MATLAB Compiler SDK) page 2-6 ff doesn't work.
Do you can help me?
Best Regards
R.-D. Therburg

Best Answer

As this document says,
>>you can either install the Python engine before running your packaged application, as described in Install MATLAB >>Engine API for Python (MATLAB), or use import mypackage before import matlab in the following programs.
that matlab module is MATLAB Engine API for Python.
In order to make "import matlab" work, we can take two options as the document explains.
  • 1) Install MATLAB Engine API for Python following the steps in this document.
Installer of MATLAB Engine API is located in matlabroot\extern\engines\python where matlabroot is install folder of MATLAB.
cd "matlabroot\extern\engines\python"
python setup.py install
Or,
  • 2) use "import mylib" before "import matlab" in your Python script.