In MATLAB I get the following python error: AttributeError: 'module' object has no attribute 'fmi'
8 次查看(过去 30 天)
显示 更早的评论
When I call my custom python function py.linFMI.run() in MATLAB R2016a I get the following error:
Error using fmi_algorithm_drivers><module> (line 28)
Python Error: AttributeError: 'module' object has no attribute 'fmi'
Error in fmi>pyfmi.fmi.ModelBase._default_options (src\pyfmi\fmi.c:6394) (line 338)
Error in fmi>pyfmi.fmi.FMUModelME2.simulate_options (src\pyfmi\fmi.c:65521) (line 6515)
Error in linFMI>run (line 313)
opts=model.simulate_options()
The same function works fine in a windows or IPython console. Any ideas what is going wrong?
0 个评论
回答(1 个)
surya venu
2024-7-16
编辑:surya venu
2024-7-16
Hi,
It looks like the issue you're encountering is related to how MATLAB interfaces with Python and the specific module you're trying to use. Here are a few steps you can take to troubleshoot and potentially resolve the issue:
1) Make sure that Python version that you are using is compatible with MATAB R2016a, and "pyfmi" module is supported for the specified version of Python.
2) Verify Module Import: Before calling your function, verify that you can import the pyfmi module in MATLAB:
py.pyfmi
3) Check Python Path: Ensure that the Python path in MATLAB includes the directory where the "pyfmi" module is installed. You can add the path using:
if count(py.sys.path,'<path_to_pyfmi_module>') == 0
insert(py.sys.path,int32(0),'<path_to_pyfmi_module>');
end
4) Debugging in MATLAB: Add debugging statements in your MATLAB code to print the Python path and check if the "pyfmi" module is being correctly imported:
disp(py.sys.path);
pyfmi = py.importlib.import_module('pyfmi');
disp(py.list(pyfmi));
Hope it helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!