python interface to MATLAB Runtime

36 次查看(过去 30 天)
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

采纳的回答

Kojiro Saito
Kojiro Saito 2018-12-29
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 个评论
Therry
Therry 2019-1-3
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 2022-8-31
编辑:Alan Frankel 2022-8-31
I believe Therry meant to write "compiler_sdk" rather than "compiler_sdm".

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Python Package Integration 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by