"No module named 'matlab.engine'; 'matlab' is not a package"
Show older comments
Hi everyone,
I'm trying to set up a connection between my python and matlab scripts. However i'm having some difficulties with the matlab module for python. I'm using a windows 10 computer and followed these instructions to install the python API for matlab: https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
I keep getting this error: "No module named 'matlab.engine'; 'matlab' is not a package"
The matlab module was succesfully installed using the latest version of pip.
I searched the internet but no given solution could help me. Any ideas?
Greetings,
Jeroen
1 Comment
pengze zhu
on 29 May 2020
Hi,
I'm using R2017b and Python3.5.I have the same problem too.
Accepted Answer
More Answers (13)
Stephan
on 15 Jan 2018
2 votes
Hi,
at last I was able to solve the problem for my case. After I have checked several times that the installation was successful: i.e. Matlab appears in the "Site packages" in the Python installation:
In Idle-> under "File"-> "Path Browser" Check whether the directory containing the MATLAB package is indeed on this path and verify that "MATLAB: Package" shows up when you expand that directory.
After this was the case, I found that my test file had the name "matlab.py". Since the import command of Python first searches for a corresponding py file and then after packages, I was able to solve the problem by renaming the file. Now it works perfectly.
This also explains why it worked on the command line with the direct input of the corresponding commands but did not work out of a development environment when I used my file called matlab.py.
2 Comments
Ankit Jaiswal
on 13 Feb 2020
This reply is very tough to understand. Not sure where you are talking about idle etc. Can you please explain it more clearly. Thanks.
Milena Mori
on 23 Jan 2021
I had also named my file 'matlab.py' and after changing it, it finally worked! Thank you so much!
Deepak Dhillon
on 11 Mar 2020
2 votes
I also face the same problem. I have MATLAB 2019b installed, anaconda installed, and spyder installed. I guess there could be some path issues, but could not spot it exactly. Kindly help.


5 Comments
Ankit Jaiswal
on 11 Mar 2020
Edited: Ankit Jaiswal
on 11 Mar 2020
I had the same problem. The solution to that problem is
1) First use Python 3.5 and not Python 3.7 as MATLAB engine is not supported for Python 3.7
2) I have seen that MATLAB Engine doesnt work in Anaconda. I was using Anaconda previously and tried everything and it didn't work for me but as soon as I shifted to Pycharm, the same code worked for me so I recommend using Pycharm. In Pycharm please give the path of Script and Interpretor properly.
3) If it's still not working for you then you have to copy the files of MATLAB engine to your working directory.One folder you should find in MATLAB directory and other in Anaconda or where you have your python.exe file. I don't know the exact link but you can search for matlabengine.py. You should find this at 2 places, one in MATLAB and other in Python. Copy both these folders ( full folders with name matlab and python) to your working directory. With this the error should go. It worked for me.
uchiha
on 21 Mar 2020
1) The page does say, that 3.6 is supported. Although 3.7 is not.
2) When you say path of script and interpretor, should this be added to the "path" variable of environment variable. Also I have the following, out of which 2 area conda interpreters, so I think I should use the other?
3) I could not find "matlabengine.py" file in the anaconda3 folder that I have which has python.exe file.
Could you please tell, what and where exactly should I find which file in anaconda3?
Diego Quan
on 25 Feb 2021
This solved it for me (Using python3.8)
I have a very similar setup (Anaconda environment with Spyder).
If I did as indicated "python setup.py install", it would use python2.7 by default. However, the main python interpreter in my environment is python3.8.
So I re did it like this:
"sudo ~/path_to_the_right_python/python setup.py install"
Jieqiang Wei
on 4 Mar 2021
@Diego Quan It works for me!
Rubem Pacelli
on 16 Dec 2021
Edited: Rubem Pacelli
on 16 Dec 2021
I could replicate it on Linux too. First, on the terminal, type
pip list | grep matlab
You should not see anything... You must to go to
[matlab_root_directory]/extern/engines/python
where [matlab_root_directory] is your installation directory. Then you simply type
sudo python setup.py install
Now, run again
pip list | grep matlab
You should see that there is a package whose name is
matlabengineforpython R2021a
where R2021a shall vary depending on your matlab version.
Florian Ruther
on 5 May 2020
1 vote
I just want to add what solved my problem.
I had to install the matlab engine with an admin account. Therefore the necessary files were put in the AppData\Local\Programs\Python\Python36 - folder of the admin account. After I copied everything from there to the corresponding folder of my user account it worked.
2 Comments
Mohd Toaha Umar
on 12 Aug 2020
Thank you, Florian. It worked for me
Metehan Bolat
on 28 Oct 2020
I could not understand where you copied the file from where.
Vijaykumar Kudtalkar
on 14 Aug 2021
1 vote
Just found a simple way to solve this problem
run command as below in Matlab command prompt
cd (fullfile(matlabroot,'extern','engines','python'))
system('python setup.py install')
if it shows as below
running install
running build
running build_py
error: You do not have write permission in build\lib\matlab\engine
ans =
1
the go to installpath\R2021a\bin and provide write permission to the folder path including sub directories and then run the command in python command prompt
import matlab.engine
It worked for me.
1 Comment
Deepika
on 8 Oct 2021
Can u plz tell me how to give write permission becoz I m facing dis issue
Steven Lord
on 23 Oct 2017
0 votes
Which release are you using? Is it older than release R2014b? Note that the page you referenced states, in part: "Your system has a supported version of Python and MATLAB R2014b or later."
Jeroen Vancraen
on 23 Oct 2017
0 votes
diadochos
on 14 Dec 2017
0 votes
You could check if you have been successful installing the module. i.e. go to the directory that's explained in the URL you pasted: https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
and run "python setup.py install".
In my case, with MATLAB R2015b release, I got the following error message:
OSError: MATLAB Engine for Python supports Python version 2.7, 3.3 and 3.4, but your version of Python is 3.6
Since you may have missed the message, you could try to install it again.
Hi,
i have the same problem using Windows 10, Matlab 2017a and Python 3.5 (same using 2.7 - then used 3.5). What can i do to solve this?

2017-12-27 Update: When starting Python directly in the command window, it is working fine with the "isprime(37)" example from Mathworks Documentation Site.
But it doesnt work when calling a .py-File. Who can help?
Raghu Ram Theerthala
on 22 Nov 2019
0 votes
May be the error is trying to install in conda environment. Check it. if that's the case, deactivate conda and run setup.py install command again. This time it should run.
2 Comments
sun mengxin
on 26 Nov 2019
this worked for me, thanks
Vidya Kurada
on 3 Feb 2021
how to do this.Any steps?
Eric Aw
on 15 Sep 2021
I have literally did everything suggested by in this page. But it is still not working for me .
I have type :
cd (fullfile(matlabroot,'extern','engines','python'))
system('python setup.py install')
in MATLAB, in cmd, everything installed perfectly . Even try this too :
python setup.py build --build-base=$(mktemp) install
But I still get the error of no module named 'matlab.engine'
Is there still any other suggestions?
3 Comments
Ankit Jaiswal
on 15 Sep 2021
Try to run it on the same code on Pycharm. It should work. Also check my previous answer on this thread. I hope you have done that.
Eric Aw
on 15 Sep 2021
@Ankit Jaiswal Thank you very much !! It finally worked !! Seriously they really should include this step in the guide !
Ankit Jaiswal
on 15 Sep 2021
That's very nice to hear 😊😊😊
Shuaiwen Huang
on 27 Apr 2022
0 votes
I tried the methods above and in Ubuntu it can find my package, but I dont know why it doesn't work in Spyder, I've changed tha path too, do anyone have any ideas please?
Maria Bardales Velasquez
on 22 May 2022
0 votes
Yo tenía el mismo problema por 3 días, nada funcionaba. Pero probé cambiar de versión de python en un nuevo ambiente de anaconda.
Uso matlab 2020a y ambiente de anaconda python versión 3.6.13


I found multiple MATLAB documentatons to install matlabengine.
----
This one which runs `python install setup.py` does not work for me. Probably because because installing with setup.py is now discouraged.
----
python -m pip install matlabengine
(or simply `pip install matlabengine` if you are sure the version of python pip is installing into)
---
I probably followed the first one at some point and I do have matlabengine as a python package but it cannot be imported
$ pip list | grep matlab
```
matlab 0.1
matlabengine 24.1
```
I have to uninstall the previous matlabengine package
pip uninstall matlabengine
and then run the second method
pip install matlabengine
Now in python, I can successfully import matlab.engine
Categories
Find more on Call MATLAB from Python in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!