How do I properly install Matlab Engine using the anaconda package manager for Python?
Afficher commentaires plus anciens
At the moment, I'm running Python 3.5 and Matlab R2015a on a 64-bit Windows 10 laptop. I'm using Anaconda as my Python package manager and want to run some Matlab scripts from Python using . I've used the classic Anaconda command to install Matlab engine:
conda install matlab_engine
However, even after Matlab engine has supposedly been installed, I get an error message whenever I type in the following command to Python.
import matlab.engine
The error just reads "no module called matlab". I'm really unsure of what to do. Am I doing something blatantly incorrect or is there another way I can install Matlab engine.
Thank you for your help.
1 commentaire
Jon
le 15 Août 2017
When I try to run your
conda install matlab_engine
command, I get a PackageNotFoundError, and it doesn't install. Are you sure it's installed?
Réponses (6)
Eli127
le 13 Sep 2018
Open Anaconda Prompt (make sure you have the correct python version):
cd matlabroot\extern\engines\python
python setup.py install
'matlabroot' is your MATLAB root directory. In my case it is 'C:\Program Files\MATLAB\R2018a'
10 commentaires
Alan Akin
le 26 Avr 2019
But then what? I have the same problem as Jon. Now it is year 2019
Mostafa Elsaadouny
le 5 Nov 2019
You should follow the above mentioned step
cd matlabroot\extern\engines\python
python setup.py install
and then start anaconda and type import matlab.engine, it will definetly work
Amin Atashnezhad
le 28 Fév 2020
I get the following error:
error: You do not have write permission in build\lib\matlab\engine\
any suggestion? can't run as admin!
wallflower
le 13 Mai 2020
I, on the other hand, do not find the directory engines...
Any ideas what I did wrong?
Thanks in advance
Eli127
le 14 Mai 2020
Run matlabroot in MATLAB to find the directory.
wejden hammami
le 26 Mai 2020
what can i do if i have Python 3.7 and matlab R2016a ?
Adithya Viswanthan
le 11 Août 2020
Modifié(e) : Adithya Viswanthan
le 11 Août 2020
@Eli127, I am currently using R2018a on MacOS Catalina 10.15.5 and am also using Python 3.7.
I followed the documentation and did the following steps;
cd matlabroot\extern\engines\python
python setup.py install
and i get the following error:
"Traceback (most recent call last):
File "setup.py", line 15, in <module>
'is %s' % _version)
OSError: MATLAB Engine for Python supports Python version 2.7, 3.5 and 3.6 but your version of Python is 3.7"
Do i have to install newer version of MATLAB? 2019 or 2020 to make use of Matlab engine with python 3.7?
Looking forward to a positive response.
MD. FAHIM SAHARIAR ALAM ABIR
le 19 Août 2020
Try to set up a new environment:
conda create -vv -n jmatlab python=3.5 jupyter
This trick worked for me.
Trevor Vannoy
le 20 Oct 2020
Modifié(e) : Trevor Vannoy
le 20 Oct 2020
In addition to what MD. FAHIM SAHARIAR ALAM ABIR said about creating a conda environment with the correct version of python for what your version of MATLAB supports, I also needed to change some folder permissions for setup.py to work on Linux. In particular, I had to take ownership of the "build" folder in "matlabroot/extern/engines/python", as running with setup.py with sudo does not keep my conda environment.
In short, here's what I did:
conda create -n matlab python=3.7
conda activate matlab
cd <matlabroot>/extern/engines/python
mkdir build
sudo chmod 777 build
python setup.py install
Doing that, the matlabengine was installed in my conda env's site-packages.
Burak
le 18 Juin 2019
I think conda doesn't have a package named "matlab_engine".
I was able to run matlab functions within the python. I installed the module with a slight variation on Ubuntu 16.04:
cd matlabroot/extern/engines/python
python setup.py install --prefix "<anaconda installation directory>"
As a general advice, just make sure that matlab module is installed in a folder where your python can see it (i.e. sys.path contains the directory of installation).
2 commentaires
Elizabeth Huaroc
le 4 Fév 2021
Thank you! That is exactly the trick! I followed the instructions on the Mathworks website, but before
import matlab.engine
I just add the folder where the matlab module was installed to my sys.path.
Where is my matlab module install?
In the terminal, after
python setup.py install
the installation folder is mentioned. For me it was something like "...anaconda3/lib/python3.8/site-packages".
Daria Ri
le 12 Mai 2021
Thank you! You're a life saver! Worked for me after days of trying
Steven Lewis
le 26 Juin 2024
2 votes
I am using MATLAB R2024a and anaconda v24.1.2. I am trying to install matlab.engine on a specific anaconda environment, but when I naviagte to the setup.py file in the matlabroot directory tree I get the error:
C:\Users\steve\.conda\envs\3d_model_analysis\Lib\site-packages\setuptools\_distutils\cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` directly.
Instead, use pypa/build, pypa/installer or other
standards-based tools.
See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
********************************************************************************
!!
self.initialize_options()
C:\Users\steve\.conda\envs\3d_model_analysis\Lib\site-packages\setuptools\_distutils\cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` and ``easy_install``.
Instead, use pypa/build, pypa/installer or other
standards-based tools.
See https://github.com/pypa/setuptools/issues/917 for details.
********************************************************************************
!!
self.initialize_options()
TEST FAILED: C:Users\steve\.conda\pkgs\Lib\site-packages\ does NOT support .pth files
bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
C:Users\steve\.conda\pkgs\Lib\site-packages\
and your PYTHONPATH environment variable currently contains:
''
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
https://setuptools.pypa.io/en/latest/deprecated/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
C:\Users\steve\.conda\envs\3d_model_analysis\Lib\site-packages\setuptools\command\sdist.py:117: SetuptoolsDeprecationWarning: `build_py` command does not inherit from setuptools' `build_py`.
!!
********************************************************************************
Custom 'build_py' does not implement 'get_data_files_without_manifest'.
Please extend command classes from setuptools instead of distutils.
See https://peps.python.org/pep-0632/ for details.
********************************************************************************
!!
self._add_data_files(self._safe_data_files(build_py))
zip_safe flag not set; analyzing archive contents...
matlab.__pycache__.__init__.cpython-311: module references __file__
matlab.__pycache__.__init__.cpython-311: module references __path__
matlab.engine.__pycache__.__init__.cpython-311: module references __file__
(3d_model_analysis) C:\Program Files\MATLAB\R2024a\extern\engines\python>python setup.py install --prefix "C:/Users/steve/.conda/pkgs"
C:\Users\steve\.conda\envs\3d_model_analysis\Lib\site-packages\setuptools\_distutils\cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` directly.
Instead, use pypa/build, pypa/installer or other
standards-based tools.
See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
********************************************************************************
!!
self.initialize_options()
C:\Users\steve\.conda\envs\3d_model_analysis\Lib\site-packages\setuptools\_distutils\cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` and ``easy_install``.
Instead, use pypa/build, pypa/installer or other
standards-based tools.
See https://github.com/pypa/setuptools/issues/917 for details.
********************************************************************************
!!
self.initialize_options()
TEST FAILED: C:Users\steve\.conda\pkgs\Lib\site-packages\ does NOT support .pth files
bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
C:Users\steve\.conda\pkgs\Lib\site-packages\
and your PYTHONPATH environment variable currently contains:
''
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
https://setuptools.pypa.io/en/latest/deprecated/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
C:\Users\steve\.conda\envs\3d_model_analysis\Lib\site-packages\setuptools\command\sdist.py:117: SetuptoolsDeprecationWarning: `build_py` command does not inherit from setuptools' `build_py`.
!!
********************************************************************************
Custom 'build_py' does not implement 'get_data_files_without_manifest'.
Please extend command classes from setuptools instead of distutils.
See https://peps.python.org/pep-0632/ for details.
********************************************************************************
!!
self._add_data_files(self._safe_data_files(build_py))
zip_safe flag not set; analyzing archive contents...
matlab.__pycache__.__init__.cpython-311: module references __file__
matlab.__pycache__.__init__.cpython-311: module references __path__
matlab.engine.__pycache__.__init__.cpython-311: module references __file__
Ehsan Shahini
le 20 Mai 2021
In linux:
First activate your environment:
conda activate
Then simply install the engine:
cd /usr/local/MATLAB/R2020b/extern/engines/python
python setup.py install
This worked for me.
1 commentaire
Caleb Berggren
le 2 Fév 2023
This worked great and was very easy.
Alberto Bortoni
le 20 Déc 2022
0 votes
This may be a workaround but it def works
To ensure that the right python via anaconda is accesed by matlab (and for that matter other programs)
open the anaconda prompt. activate any environment you desire (or stay in base). Then open matlab from within by typing "matlab" (no quotes)
Archana
le 9 Sep 2025
0 votes
Hello, i am working on the matlab simulink model, where i run the model and i can see the scopes running lively. how can i stream it to get the same matlab live plots using streamlit to show in the dahboard?
i want to run the model in matlab and at the same time i want to see the live plots in the dashboard. is it possible?
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!