Clear Filters
Clear Filters

In MATLAB I get the following python error: AttributeError: 'module' object has no attribute 'fmi'

5 views (last 30 days)
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?

Answers (1)

surya venu
surya venu on 16 Jul 2024 at 6:02
Edited: surya venu on 16 Jul 2024 at 6: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.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!