Package: matlabengine
MATLAB Engine API for PythonThe MATLAB® Engine API for Python® provides a package to integrate MATLAB functionality directly with a Python application, creating an interface to call functions from your MATLAB installation from Python code.RequirementsRequired MathWorks ProductsMATLAB release R2023bRequired 3rd Party ProductsPython 3.9, 3.10, or 3.11Supported Python versions by MATLAB release can be foundhere.InstallWindowsMATLAB Engine API for Python can be installed directly from the Python Package Index.$python-mpipinstallmatlabengine==23.2.2Linux®Prior to installation, check the default install location of MATLAB by callingmatlabrootin a MATLAB Command Window. By default, Linux installs MATLAB at:/usr/local/MATLAB/R2023bWhen MATLAB is not installed in the default location, the bin/architecturedirectory within the MATLAB root directory must be added to the environment variable LD_LIBRARY_PATH. The path can be added to the environment variable within the shell startup configuration file (for example, .bashrc for bash shell or .tcshrc for tcsh).# in .bashrcexportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:<matlabroot>/bin/glnxa64# in .tcshrcsetenvLD_LIBRARY_PATH${LD_LIBRARY_PATH}:<matlabroot>/bin/glnxa64MATLAB Engine API for Python can be installed directly from the Python Package Index.$python-mpipinstallmatlabengine==23.2.2macOSPrior to installation, check the default install location of MATLAB by callingmatlabrootin a MATLAB Command Window. By default, macOS installs MATLAB at:/Applications/MATLAB_R2023b.appWhen MATLAB is not installed in the default location, the bin/architecturedirectory within the MATLAB root directory must be added to the environment variable DYLD_LIBRARY_PATH. The path can be added to the environment variable within the shell startup configuration file (for example, .bashrc for bash shell or .tcshrc for tcsh).# in .bashrcexportDYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:<matlabroot>/bin/maci64# in .tcshrcsetenvDYLD_LIBRARY_PATH${DYLD_LIBRARY_PATH}:<matlabroot>/bin/maci64MATLAB Engine API for Python can be installed directly from the Python Package Index.$python-mpipinstallmatlabengine==23.2.2Getting StartedStart Python.Import thematlab.enginepackage into the Python session.Start a new MATLAB process by callingstart_matlab. Thestart_matlabfunction returns a Python object which enables you to pass data and call functions executed by MATLAB.>>>importmatlab.engine>>>eng=matlab.engine.start_matlab()>>>eng.sqrt(4.0)2.0Call either theexitorquitfunction to stop the engine. Exiting Python with an engine running stops the engine and its MATLAB processes.>>>eng.quit()SeeStart and Stop MATLAB Engine for Pythonfor advanced startup examples.ExamplesYou can call any MATLAB function directly and return the results to Python.>>>eng.plus(2,3)5>>>eng.isprime(37)True>>>eng.gcd(100.0,80.0,nargout=3)(20.0,1.0,-1.0)SeeCall MATLAB Functions from Pythonfor more usage examples.LimitationsLimitations of the MATLAB Engine API for Python can be foundhere.TroubleshootingSeeTroubleshoot MATLAB Errors in Pythonfor troubleshooting assistance.LicenseThe license is available in the LICENSE.txt file within this repository.SupportTechnical issues or enhancement requests can be submittedhere.Copyright © 2022 MathWorks, Inc. All rights reserved.Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.Mac OS is a trademark of Apple Inc., registered in the U.S. and other countries."Python" and the Python logos are trademarks or registered trademarks of the Python Software Foundation, used by MathWorks with permission from the Foundation.