当前位置:网站首页>pycharm中调用Matlab配置:No module named ‘matlab.engine‘; ‘matlab‘ is not a package
pycharm中调用Matlab配置:No module named ‘matlab.engine‘; ‘matlab‘ is not a package
2022-08-05 05:13:00 【吃饱了就很强】
使用Pycharm配置调用matlab经验分享,浏览大量帖子总结出来,主要是这篇文章:python调用matlab的方法记录
matlab2018b支持python3.5、3.6但是不支持python3.7。如果遇到不匹配的情况,记得把python的版本降低,或者安装更新版本的matlab,比如:matlab2020b
1. 首先找到matlab安装路径,我的路径在:D:\matlab2020b\extern\engines\python,如下:
这是安装成功后的目录
2. 利用命令行,cmd,到D:\matlab2020b\extern\engines\python文件夹下,然后依次执行下面命令。
python setup.py build --build-base="builddir" install
python setup.py install --prefix="installdir"
python setup.py build --build-base="builddir" install --prefix="installdir"
python setup.py install --user
例如:
安装成功后利用下面的代码测试是否能够运行:
import matlab.engine
from numpy import *
if __name__ == '__main__':
eng = matlab.engine.start_matlab('MATLAB_R2019b')
A = matlab.double([[1, 2], [5, 6]])
print(type(A), A.size, A)
print(eng.eig(A))
eng.quit()
pass
如果测试报错:No module named ‘matlab.engine’; ‘matlab’ is not a package
记得查看python解释器路径里面是否有生成matlab文件,例如下面的图片:
D:\python3.7\venv\Lib\site-packages\matlab
如果没有,那么把D:\matlab2020b\extern\engines\python下的dist中的matlab文件复制python解释器路径。
如果还是报错,可能的原因如下:
1.复制的路径不对,检查python解释器路径。
2.D:\matlab2020b\extern\engines\python路径下的matlab的包错误,导致出现问题。重新安装或者直接找一个已经安装好的matlab复制到python解释器路径。
链接:https://pan.baidu.com/s/1t3fOUrCsh_MHdwludo7h8w
提取码:rjle
–来自百度网盘超级会员V4的分享
python里调用matlab脚本,参考:参考
matlab中编写:
function hellomatlab()
clear
sum = 0;
for i = 1:100
sum = sum +i;
disp(['sum=',num2str(sum)]);
end
pycharm中编写:
import matlab
import matlab.engine
engine = matlab.engine.start_matlab() # 启动matlab engine
engine.hellomatlab(nargout = 0)
注意:matlab代码和python代码需要在同一目录下
调用结果:
边栏推荐
猜你喜欢
[Study Notes Dish Dog Learning C] Classic Written Exam Questions of Dynamic Memory Management
多线程查询结果,添加List集合
【转】什么是etcd
二叉树基本性质+oj题解析
RL强化学习总结(一)
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
coppercam primer [6]
【cesium】加载并定位 3D Tileset
u-boot debugging and positioning means
flex布局青蛙游戏通关攻略
随机推荐
How to quickly upgrade your Taobao account to a higher level
Transformation 和 Action 常用算子
Flutter学习2-dart学习
Flutter真机运行及模拟器运行
The difference between span tag and p
Judgment statement _switch and case
Requests the library deployment and common function
【过一下8】全连接神经网络 视频 笔记
Structured light 3D reconstruction (1) Striped structured light 3D reconstruction
[Study Notes Dish Dog Learning C] Classic Written Exam Questions of Dynamic Memory Management
【技能】长期更新
Analysis of Mvi Architecture
仪表板展示 | DataEase看中国:数据呈现中国资本市场
[Decoding tools] Some online tools for Bitcoin
Excel Paint
Flutter 父子组件如何都能收到点击事件
The role of DataContext in WPF
Difference between for..in and for..of
【解码工具】Bitcoin的一些在线工具
Dashboard Display | DataEase Look at China: Data Presents China's Capital Market