3 July 2019 at 15 h 34 min #13900
I have a question regarding numpy library in SOFA. It seems that SOFA have created a SOFAnumpy library. IS this true? So when I want to import numpy in my code, should I import “SofaPython.SofaNumpy”? I am asking this because if I just import numpy in my code, I receive this import error:
“from . import _distributor_init
ImportError: cannot import name _distributor_init”
To my knowledge, this happens because of two numpy library installation, one from the Anaconda and one from SOFA, however, I couldn’t solve this issue.
Does anybody know which version of numpy SOFA is using?
Thanks in advance for any guidance.
Zahra4 July 2019 at 17 h 34 min #13905
Sofa does not package numpy with its sources, so your problem, while indeed being an issue with concurrent versions of numpy on your system, is not linked to your install of SOFA. (as far as I know)
I’m no expert in this, but I’d guess that:
– you installed numpy either via your package manager (apt install python-numpy) or via pip (pip install numpy)
– then installed Anaconda, which does, of course, redistributes its own version of python.
I *think* that you might be able to fix your issue by uninstalling numpy’s pip (or aptitude) package (using pip uninstall or apt remove).
It seems that you dug a bit in the SofaPython plugin before posting, that’s nice 😉
There’s indeed an example called SofaNumpy in SofaPython, which uses a piece of python code that imports numpy. But this script relies on your system’s install of numpy, so as said before, it should not be the cause of your problem.
That being said, it seems that the SofaNumpy code is supposed to provide shared-memory pointer access to Sofa’s data fields through a numpy array abstraction, which is a must-have feature IMHO. The code does not seem to be functional though, sadly.
I actually never realized that there was a SofaNumpy module present in SofaPython, it’s a pretty cool discovery for me. If you have the skills and feel like restoring this code, feel free to do so, we’ll be more than happy to see such a pull request in SOFA!
Meanwhile, we are working on a similar approach in the next gen SofaPython3 plugin whose beta version should be released soon… *teaser*
Anyway, I hope this answers your question, and best of luck!10 July 2019 at 18 h 08 min #13927
Dear @Bruno Marques,
Thank you for your kind reply, and sorry for the late reply, my code were running so I couldn’t try your hint and give you the feedback sooner.
I tried your hints, I uninstalled everything, including Anaconda and numpy, until there was no numpy there. I then reinstalled Anaconda, and the problem persists. At least it’s helpful to know that it has nothing to do with SOFA libraries. May I ask if you are using Anaconda for python scripting?
Thanks for your explanation on SofaNumpy, and on your news about SofaPython3. Would SofaPython3 plugin have this feature that we can import sofa module directly in Spyder?
Regarding restoring the mentioned code, thank you for encouraging me. I would like to contribute SOFA and challenge myself in the pull requesting, but restoring this code doesn’t motivate me that much. I also didn’t feel that confident at this moment for it.
Zahra3 August 2019 at 20 h 31 min #14057
- CNRS/Defrost Team
On my side I don’t use Anaconda and prefer to rely on pip as much as I can.
About SofaPython3. The answer is yes, it make it possible to import Sofa modules and run a simulation directly in any python interpreter (Jupyter, Spyder, python3) in addition to the embedded one in runSofa.
Damien.24 August 2019 at 15 h 35 min #14154
Thank you for your explanations on SofaPython3. It looks great!
Zahra24 August 2019 at 15 h 42 min #14155
My problem with importing numpy has solved. In my case, the problem was that the default python in my system wasn’t the one that SOFA is using. Changing the default python removed the error.
You must be logged in to reply to this topic.