python interface to MATLAB Runtime

36 ビュー (過去 30 日間)
Therry
Therry 2018 年 12 月 28 日
編集済み: Alan Frankel 2022 年 8 月 31 日
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 Center および File ExchangePython Package Integration についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by