python interface to MATLAB Runtime

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

 Risposta accettata

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.

2 Commenti

Hello,
the problem comes not from the MATLAB engine but from the MATLAB Runtime on the target machine. So both ways doesn't help, but the solution is something like that.
With "python setup.py install" I can install my python library generated with the Compiler SDK. But the MATLAB Runtime itself was not installed in Python. I found another setup.py in the Runtime:
cd "mcrroot\v95\toolbox\compiler_sdm\pysdk_py"
than execute: "python setup.py install"
After that "import matlab" works and I can generate MATLAB arrays with matlab.double etc.like the examples in the Pythons User's guide (MATLAB Compiler SDK) page 2-6 ff.
Best Regards
R.-D. Therburg
Alan Frankel
Alan Frankel il 31 Ago 2022
Modificato: Alan Frankel il 31 Ago 2022
I believe Therry meant to write "compiler_sdk" rather than "compiler_sdm".

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by