matlab python engine module not recognized

조회 수: 5 (최근 30일)
Shiping Yi
Shiping Yi 2019년 7월 29일
답변: Meet 2025년 1월 17일
I am having trouble using the matlab python engine. I tried this piece of code from the mathworks website:
import matlab.engine
if __name__ == '__main__':
eng = matlab.engine.start_matlab()
x = 4.0
eng.workspace['y'] = x
a = eng.eval('sqrt(y)')
print(a)
pass
But pycharm is giving me an error saying "ModuleNotFoundError: No module named 'matlab.engine'; 'matlab' is not a package". I am using python 3.6 and matlab 2018. I saw that these are the supported versions on website, I saw a similar post about this problem but I can't even run my program from python command line. I also can't find teh matlab.py in my python site-packages, although I have the matlab folder in packages.

답변 (1개)

Meet
Meet 2025년 1월 17일
Hi Shiping,
To resolve this issue, you need to install the MATLAB Engine API for Python:
First ensure that you have correct version of python installed and accessible using command line.
Then open a command prompt and navigate to the MATLAB engine directory:
cd "matlabroot\extern\engines\python"
Replace 'matlabroot' with your MATLAB installation directory.
Install MATLAB API using 'pip' command:
python -m pip install .
To get the detailed instructions on the same, please follow this documentation link:

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by