CATIA-Systems / FMPy

Simulate Functional Mockup Units (FMUs) in Python
Other
429 stars 118 forks source link

fmpy.sundials not importable on MacOS Apple Silicon in version 0.3.20 #661

Open miki5799 opened 6 months ago

miki5799 commented 6 months ago

After installing fmpy(0.3.20) via pip (3.9.19 , 3.10.14, 3.12.2 respectively) on my MacOS machine (Apple Silicon M1) the following error occurs when attempting to import the fmpy.sundials module:

>>> import fmpy.sundials
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/__init__.py", line 4, in <module>
    from .cvode import *
  File "<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/cvode.py", line 1, in <module>
    from .libraries import sundials_cvode
  File "<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/libraries.py", line 8, in <module>
    sundials_nvecserial     = cdll.LoadLibrary(os.path.join(library_dir, platform_tuple, 'sundials_nvecserial'     + sharedLibraryExtension))
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib, 0x0006): tried: '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file)>>> import fmpy.sundials
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/__init__.py", line 4, in <module>
    from .cvode import *
  File "/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/cvode.py", line 1, in <module>
    from .libraries import sundials_cvode
  File "/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/libraries.py", line 8, in <module>
    sundials_nvecserial     = cdll.LoadLibrary(os.path.join(library_dir, platform_tuple, 'sundials_nvecserial'     + sharedLibraryExtension))
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib, 0x0006): tried: '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file)

installing sundials with brew did not resolve this

Note that this happens only in version 0.3.20

t-sommer commented 5 months ago

Did you install the pre-built wheel from PyPI with python -m pip install fmpy==0.3.20?

If so, can you successfully import fmpy.sundials with FMPy 0.3.19 on Apple Silicon?

miki5799 commented 4 months ago

Sorry for the late reply. As of today I am able to successfully import the mentioned module with both FMPy 0.3.19 and 0.3.20

miki5799 commented 3 months ago

It seems like this issue is reappearing since I am again not able to import the sundials package from fmpy==0.3.20

t-sommer commented 3 months ago

Can you share the error message?

miki5799 commented 3 months ago
>>> import fmpy.sundials
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/__init__.py", line 4, in <module>
    from .cvode import *
  File "<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/cvode.py", line 1, in <module>
    from .libraries import sundials_cvode
  File "<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/libraries.py", line 8, in <module>
    sundials_nvecserial     = cdll.LoadLibrary(os.path.join(library_dir, platform_tuple, 'sundials_nvecserial'     + sharedLibraryExtension))
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(<PathToRepo>/.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib, 0x0006): tried: '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file)>>> import fmpy.sundials
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/__init__.py", line 4, in <module>
    from .cvode import *
  File "/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/cvode.py", line 1, in <module>
    from .libraries import sundials_cvode
  File "/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/libraries.py", line 8, in <module>
    sundials_nvecserial     = cdll.LoadLibrary(os.path.join(library_dir, platform_tuple, 'sundials_nvecserial'     + sharedLibraryExtension))
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib, 0x0006): tried: '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/<PathToRepo>//.test/lib/python3.9/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file)
t-sommer commented 3 months ago

This looks exactly like the original error message. Did you install the pre-built wheel from PyPI?

miki5799 commented 3 months ago

This looks exactly like the original error message. Did you install the pre-built wheel from PyPI?

Yes, I've tried it again in another environment:

MacBook-Air ~ % rm -rf .venv
MacBook-Air ~ % python -m venv .venv
MacBook-Air ~ % source .venv/bin/activate
(.venv) MacBook-Air ~ % pip cache purge
Files removed: 3246
(.venv) MacBook-Air ~ % pip install fmpy
Collecting fmpy
  Downloading FMPy-0.3.21-py3-none-any.whl.metadata (2.0 kB)
Collecting attrs (from fmpy)
  Downloading attrs-23.2.0-py3-none-any.whl.metadata (9.5 kB)
Collecting Jinja2 (from fmpy)
  Downloading jinja2-3.1.4-py3-none-any.whl.metadata (2.6 kB)
Collecting lark (from fmpy)
  Downloading lark-1.1.9-py3-none-any.whl.metadata (1.9 kB)
Collecting lxml (from fmpy)
  Downloading lxml-5.2.2-cp312-cp312-macosx_10_9_universal2.whl.metadata (3.4 kB)
Collecting msgpack (from fmpy)
  Downloading msgpack-1.0.8-cp312-cp312-macosx_11_0_arm64.whl.metadata (9.1 kB)
Collecting numpy (from fmpy)
  Downloading numpy-2.0.0-cp312-cp312-macosx_14_0_arm64.whl.metadata (60 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.9/60.9 kB 4.1 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0 (from Jinja2->fmpy)
  Downloading MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl.metadata (3.0 kB)
Downloading FMPy-0.3.21-py3-none-any.whl (6.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.7/6.7 MB 27.3 MB/s eta 0:00:00
Downloading attrs-23.2.0-py3-none-any.whl (60 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.8/60.8 kB 7.2 MB/s eta 0:00:00
Downloading jinja2-3.1.4-py3-none-any.whl (133 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.3/133.3 kB 6.9 MB/s eta 0:00:00
Downloading lark-1.1.9-py3-none-any.whl (111 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 111.7/111.7 kB 12.8 MB/s eta 0:00:00
Downloading lxml-5.2.2-cp312-cp312-macosx_10_9_universal2.whl (8.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.2/8.2 MB 13.7 MB/s eta 0:00:00
Downloading msgpack-1.0.8-cp312-cp312-macosx_11_0_arm64.whl (85 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.4/85.4 kB 8.3 MB/s eta 0:00:00
Downloading numpy-2.0.0-cp312-cp312-macosx_14_0_arm64.whl (5.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.0/5.0 MB 12.9 MB/s eta 0:00:00
Downloading MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl (18 kB)
Installing collected packages: numpy, msgpack, MarkupSafe, lxml, lark, attrs, Jinja2, fmpy
Successfully installed Jinja2-3.1.4 MarkupSafe-2.1.5 attrs-23.2.0 fmpy-0.3.21 lark-1.1.9 lxml-5.2.2 msgpack-1.0.8 numpy-2.0.0
(.venv) MacBook-Air ~ % python
Python 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fmpy.sundials
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/__init__.py", line 4, in <module>
    from .cvode import *
  File "<PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/cvode.py", line 1, in <module>
    from .libraries import sundials_cvode
  File "<PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/libraries.py", line 8, in <module>
    sundials_nvecserial     = cdll.LoadLibrary(os.path.join(library_dir, platform_tuple, 'sundials_nvecserial'     + sharedLibraryExtension))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 460, in LoadLibrary
    return self._dlltype(name)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: dlopen(<PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib, 0x0006): tried: '<PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS<PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file), '<PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/aarch64-darwin/sundials_nvecserial.dylib' (no such file)
>>> exit()
(.venv) MacBook-Air ~ %
t-sommer commented 3 months ago

Can you check if the file is actually missing? Can you reproduce the problem with other versions of FMPy and Python?

miki5799 commented 3 months ago

Thanks for the fast reply. Yes the file is actually missing.

As stated originally this is exclusive to fmpy 0.3.20 on at least (3.9.19 , 3.10.14, 3.12.2 respectively) on my MacOS machine (Apple Silicon M1) and sometimes it stops complaining.

t-sommer commented 2 months ago

As a quick fix, can you try to rename the folder <PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/x86_64-darwin/ to <PathToEnv>/lib/python3.12/site-packages/fmpy/sundials/aarch64-darwin/?

miki5799 commented 2 months ago

Yes that worked for me. Thanks for suggesting the quick fix, I'd still keep the issue open though

sergiochavezlazo96 commented 1 month ago

Hello! I am having exactly the same issue now (as well, only for 0.3.2). Any updates on this bug? Thank you!!