matlab python engine module not recognized

5 vues (au cours des 30 derniers jours)
Shiping Yi
Shiping Yi le 29 Juil 2019
Réponse apportée : Meet le 17 Jan 2025
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.

Réponses (1)

Meet
Meet le 17 Jan 2025
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:

Catégories

En savoir plus sur Call MATLAB from Python dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by