sofa-framework / SofaPython3

A python plugin for Sofa offering a pythonic interface and python3 support.
GNU Lesser General Public License v2.1
49 stars 46 forks source link

Import numpy error while opening .py file #460

Open fgmelo14 opened 1 month ago

fgmelo14 commented 1 month ago

Hello! I am using the SOFA_v24.06.00_MacOS binaries with python3.10

I am trying to get started using the SofaPython3 plugin but I am facing some errors. I run RunSofa and I get no problem; SofaPython3 loads correctly.

As a simple test, when I load into runSofa a simple python script with only "import numpy" I get the following error:

[DEPRECATED] [SofaPython3::SceneLoader] Unable to completely load the scene from file '/Users/digitalsurgerylab/Downloads/test.py'.  
Python exception:   
  ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.

At:
  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/__init__.py(135): <module>
  <frozen importlib._bootstrap>(241): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(883): exec_module
  <frozen importlib._bootstrap>(703): _load_unlocked
  <frozen importlib._bootstrap>(1006): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1027): _find_and_load
  /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scipy/__init__.py(47): <module>
  <frozen importlib._bootstrap>(241): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(883): exec_module
  <frozen importlib._bootstrap>(703): _load_unlocked
  <frozen importlib._bootstrap>(1006): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1027): _find_and_load
  /Users/digitalsurgerylab/Downloads/test.py(12): <module>
  <frozen importlib._bootstrap>(241): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(883): exec_module
  <string>(6): <module>

Any help fixing this would be greatly appreciated! Cheers

AlexandreLaborde commented 1 month ago

This seems to be an issue with Apple Silicon CPUs.

To resolve this issue, I opted to enforce the installation of the x86_64 architecture when installing numpy and scipy using pip. This ensured that the modules consistently imported the correct x86_64 architecture instead of ARM.

arch -x86_64 pip install numpy==1.26.0 scipy

fgmelo14 commented 1 month ago

Thank you AlexandreLaborde, it works!