PythonFMU
PythonFMU copied to clipboard
PythonFMU with NumPy
Hello,
We have noticed that, when trying to wrap some simple Python model which depends on NumPy we get following error
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/opt/ws/src/code/cosim_tools/omsimulator/build/PythonFMU"
* The NumPy version is: "1.22.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: /usr/local/lib/python3.9/dist-packages/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so: undefined symbol: PyObject_SelfIter
just after importing NumPy at the begging of the Python script
from pythonfmu import Fmi2Causality, Fmi2Slave, Real
try:
import numpy
except ImportError as e:
print(e)
Have any of you encounter similar problem before?
I once experienced issues with a specific version of numpy about 2 years ago (update fixed it). Similar issue: https://stackoverflow.com/questions/49784583/numpy-import-fails-on-multiarray-extension-library-when-called-from-embedded-pyt
I don't have a solution though. The entire Python linking stuff is a pain on linux.
Thx for pointing this out. I have solved this problem by loading shared lib libpython in PySlaveInstance but this is a workaround. With this solution each FMU is independent from master as long as python dependence are installed properly. Loading libpython in master will degradate FMU portability, and will require loading python symbols by various masters like Matlab or Modelica -- this is bad idea in my opinion.
maybe #187 will help here too
When using numpy packages in my program, export FMU and simulate using Simulink. The first execution is normal, but an exception will be reported after the second attempt. Preliminary investigation shows that it is a problem with numpy. Is there any solution? Win11 64 bit OS.