I am trying to run Matlab code using Python. I tried to follow the instructions given on this Mathworks page.
When trying to import Matlab though Python, it was installed using pip install matlab
.
However, importing matlab.engine
gives the error No module named 'matlab.engine'; 'matlab' is not a package
. It cannot be installed using pip install engine
either.
How can I get the code running? The Python code I'm running is as below:
import matlab.engine
eng = matlab.engine.start_matlab()
eng.triarea(nargout=0)
Python version - 3.5
Matlab version - 8.5.0.197613 (R2015a)
Start MATLAB Engine for PythonImport the matlab. engine package into your Python session. Start a new MATLAB® process by calling start_matlab . The start_matlab function returns a Python object eng which enables you to pass data and call functions executed by MATLAB.
There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine API for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to compile a Python package that does not require users to have a MATLAB install.
You need to install the Matlab Engine for Python, and it cannot be installed using pip. Try the instructions listed here. I have listed the instructions briefly below:
matlabroot
command within Matlab to find it.cd "matlabroot\extern\engines\python"
(In Windows)python setup.py install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With