Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonFMU with NumPy #152

Open
mariuszjaniakpl opened this issue Mar 29, 2022 · 4 comments
Open

PythonFMU with NumPy #152

mariuszjaniakpl opened this issue Mar 29, 2022 · 4 comments

Comments

@mariuszjaniakpl
Copy link

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?

@markaren
Copy link
Member

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.

@mariuszjaniakpl
Copy link
Author

mariuszjaniakpl commented Mar 30, 2022

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.

@jschueller
Copy link
Contributor

maybe #187 will help here too

@MinsGoing
Copy link

MinsGoing commented Apr 29, 2024

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.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants