python interface to MATLAB Runtime

5 Ansichten (letzte 30 Tage)
Therry
Therry am 28 Dez. 2018
Bearbeitet: Alan Frankel am 31 Aug. 2022
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

Akzeptierte Antwort

Kojiro Saito
Kojiro Saito am 29 Dez. 2018
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 Kommentare
Therry
Therry am 3 Jan. 2019
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 am 31 Aug. 2022
Bearbeitet: Alan Frankel am 31 Aug. 2022
I believe Therry meant to write "compiler_sdk" rather than "compiler_sdm".

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Python Package Integration finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by