フィルターのクリア

MATLAB Engine API for Python - ModuleNotFoundError

35 ビュー (過去 30 日間)
Leonardo Ricupero
Leonardo Ricupero 2022 年 5 月 26 日
コメント済み: Gerlise 2023 年 5 月 15 日
Hi,
I'm struggling to install and use the Matlab Engine API for Python.
Python distribution: Winpython 3.8 64 bit
Following the instructions here I'm able to correctly install the engine (no error is reported).
But when I try a simple
import matlab.engine
I get the following error:
>>>> import matlab.engine
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\lab.motori2\WPy64-38122\pypy3.8-v7.3.9-win64\lib\site-packages\matlabengineforpython-r2022a-py3.8.egg\matlab\__init__.py", line 214, in <module>
from matlabmultidimarrayforpython import double, single, uint8, int8, uint16, \
ModuleNotFoundError: No module named 'matlabmultidimarrayforpython'
Any help will be appreciated.
Thanks!

採用された回答

Kojiro Saito
Kojiro Saito 2022 年 5 月 31 日
編集済み: Kojiro Saito 2022 年 6 月 6 日
matlabmultidimarrayforpython.pyd will be found in $MATLAB_INSTALL\extern\engines\python\dist\matlab\engine\win64 folder.
Could you confirm the files? If not, your there might be an issue of MATLAB installation.
UPDATED
In some Python distributions, MATLAB Engine might not work well. If you can, how about try installing pure Python from python.org,
and try running setup install again?
In Command Prompt, run the following.
cd "$MATLAB_INSTALL\extern\engines\python"
C:\FULLPATH\TO\python.exe setup.py install --prefix="C:\Users\lab.motori2\WPy64-38122\pypy3.8-v7.3.9-win64\lib\site-packages\"
then, create a script,
test.py
import sys
sys.path.append("C:\Users\lab.motori2\WPy64-38122\pypy3.8-v7.3.9-win64\lib\site-packages\")
import matlab.engine
and execute from CPython.
C:\FULLPATH\TO\python.exe test.py
  13 件のコメント
Kojiro Saito
Kojiro Saito 2022 年 6 月 6 日
Thank you for your testing.
Some Python distributions work fine. I'm not sure what is the root cause of this issue in PyPy, but this page says, "The engine supports the reference implementation (CPython)", CPython is officially supported.
Leonardo Ricupero
Leonardo Ricupero 2022 年 6 月 6 日
Thanks for the support!

サインインしてコメントする。

その他の回答 (1 件)

Ashwin Krishnakumar
Ashwin Krishnakumar 2022 年 6 月 19 日
Hello. I have the same error.
ModuleNotFoundError: No module named 'matlabmultidimarrayforpython'
This is the output when I run "python setup.py install --user" from the folder /Applications/MATLAB_R2021a.app/extern/engines/python . My installation folder.
It seems to install perfectly.
But when I run a script with the following error occurs. This is in a mac machine,
I do not however see .pyd file after matlab python engine.
Requesting your suggestions .
  4 件のコメント
Amanda
Amanda 2022 年 10 月 13 日
If anyone encounters this error and your also get an import error with "mlarray". The issue is that with older Matlab installations (I encountered this with R2019a in both Linux and Windows), is that "mlarray" and "mlexceptions" is not located in the folders located in _ _arch.txt. To solve this, you need to edit "src/matlab/_ _ init _ _.py" :
+ sys.path.insert(0, os.path.dirname(os.path.dirname(engine_dir)))
+ from mlexceptions import ShareError, SizeError #and remove imports from mlarray
Gerlise
Gerlise 2023 年 5 月 15 日
Can you show me how your "src/matlab/__init__.py" looks like? I get the ModuleNotFoundErro: No module named "mlexceptions".

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by