问题描述
我正在尝试使用Python运行Matlab代码.我试图遵循此 Mathworks页面.
I am trying to run Matlab code using Python. I tried to follow the instructions given on this Mathworks page.
当尝试通过Python导入Matlab时,已使用pip install matlab
安装了它.
When trying to import Matlab though Python, it was installed using pip install matlab
.
但是,导入matlab.engine
会给出错误No module named 'matlab.engine'; 'matlab' is not a package
.也不能使用pip install engine
进行安装.
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.
如何使代码运行?我正在运行的Python代码如下:
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版本-3.5
Python version - 3.5
Matlab版本-8.5.0.197613(R2015a)
Matlab version - 8.5.0.197613 (R2015a)
推荐答案
您需要安装适用于Python的Matlab引擎,并且无法使用pip进行安装.请尝试在此处中列出的说明>.我在下面简要列出了说明:
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:
- 确保PATH中包含Python.
- 找到Matlab根文件夹.您可以在Matlab中使用
matlabroot
命令 来找到它. - 在命令行中转到Matlab根文件夹.
-
cd "matlabroot\extern\engines\python"
(在Windows中) -
python setup.py install
- Make sure you have Python in your PATH.
- Find the Matlab root folder. You can use the
matlabroot
command within Matlab to find it. - Go to the Matlab root folder in the command line.
cd "matlabroot\extern\engines\python"
(In Windows)python setup.py install
这篇关于使用Python运行Matlab会出现“没有名为matlab.engine的模块"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!