20 March 2020 at 17 h 13 min #15512
I just installed the SofaPython3 plugin (SP3) with out-of-tree builds following the instructions posted here:
When I open the SP3 examples from within the runSofa GUI everything works just fine. However, running a scene file (-> ReadTheDocs_Example.py) from within a python3 interpreter throws the following error:
`[ERROR] [PluginManager] Plugin not found: “SofaAllCommonComponents”
When I run the example scene ControllerScene.py in the same way, I get a few warnings saying “the library has not been initialized (sofa::simulation::common::init() has never been called, see sofa/helper/init.h)” as well as the error from the PluginManager mentioned before.
I know, the plugin is still work in progress but I was wondering if I am using it correctly? Or did I miss a step in the installation process?
My SOFA version is v19.12.
Thanks for your help!21 March 2020 at 12 h 40 min #15522
When you start a scene with the runSofa executable, Sofa looks inside the path “../lib” relative to the runSofa executable path in order to find its core plugins.
When you load Sofa inside a python interpreter, Sofa has no idea where its core plugins are, since the only path it knows is the path of the python executable (/usr/bin/python3).
You can provide the path to Sofa’s plugins by either:
1. Set the environment variable SOFA_ROOT to the location of your Sofa build directory (ie, you should be able to find the Sofa’s plugins in $SOFA_ROOT/lib).
$ export SOFA_ROOT=/home/tim/sofa/build $ python3 >>> import SofaRuntime >>> from Sofa.Core import Simulation >>> root = Simulation.load("scene.py") >>> root.init()
2. Manually add the libraries path to the PluginRepository :
$ python3 >>> from SofaRuntime import PluginRepository >>> from Sofa.Core import Simulation >>> PluginRepository.addFirstPath("/home/tim/sofa/build/lib") >>> root = Simulation.load("scene.py") >>> root.init()
3. Use the AddPluginRepository component in your scene
<AddPluginRepository path="/home/tim/sofa/build/lib" />23 March 2020 at 10 h 19 min #15523
Thanks for your reply! I cannot test it right now but I will let you know if it worked soon.23 March 2020 at 15 h 08 min #15526
I added the Sofa build directory to PATH. Trying option 1 gives the following output (same with option 2):
>>> import SofaRuntime
>>> from Sofa.Core import Simulation
[ERROR] [PythonScript] ImportError: cannot import name ‘Simulation’ from ‘Sofa.Core’ (/home/tip/.local/lib/python3.7/site-packages/Sofa/Core.cpython-37m-x86_64-linux-gnu.so)
File “<stdin>”, line 1, in <module>
Thanks for your help!23 March 2020 at 21 h 33 min #15531
My mistake, it is
from Sofa import Simulation, and not
from Sofa.Core import Simulation.
However, it seems there is a binding error on the return type of the
Simulation.load(filename)call. I’ll look into it.
For now, if you want to load this scene, first remove the line
confignode.addObject('RequiredPlugin', name="SofaPython3", printLog=False)
from the ReadTheDocs_Example.py file, go in the example directory and do something like:
$ python3 >>> import Sofa >>> import Sofa.Gui >>> import Sofa.Simulation >>> import SofaRuntime >>> from ReadTheDocs_Example import createScene >>> SofaRuntime.importPlugin('SofaOpenglVisual') >>> root = Sofa.Core.Node() >>> createScene(root) >>> Sofa.Simulation.init(root) >>> Sofa.Gui.GUIManager.Init("example", "qglviewer") >>> Sofa.Gui.GUIManager.createGUI(root) >>> Sofa.Gui.GUIManager.SetDimension(1080, 1080) >>> Sofa.Gui.GUIManager.MainLoop(root)24 March 2020 at 11 h 49 min #15538
Great, we are getting closer. 😉
Now the only thing that is still complaining is the GUIManager:
>>> Sofa.Gui.GUIManager.Init("example", "qglviewer") [ERROR] [GUIManager] No GUI registered. 1
If I type
Sofa.Gui.GUIManager.ListSupportedGUI(",")I get an empty string.
Any idea how to fix this? Thanks for your patience.24 March 2020 at 11 h 54 min #15539
Did you compile Sofa with the GUI support?
If you go inside your Sofa’s build directory, what is the output of
grep "SOFAGUI_.*VIEWER" CMakeCache.txt24 March 2020 at 12 h 13 min #15540
The output is
I am not so sure what you mean by GUI support. But, I did not change any of the preconfigured settings related to the GUI when compiling SOFA. Does that help?25 March 2020 at 20 h 20 min #15560
Sofa is a framework that can be compiled without GUI, I just wanted to make sure that you compiled the GUI part since
Sofa.Gui.GUIManager.ListSupportedGUIreturned you an empty string.
I am unsure why you cannot get the GUI running from python, but in any cases, starting the Sofa’s GUI from the python script is probably not a good idea. It will simply steal the thread from python and resume it once you close the GUI. If you want a GUI, you are better off just starting the GUI directly with the runSofa executable (sofa/build/bin/runSofa) and open your python scene from there.26 March 2020 at 9 h 58 min #15567
- You must be logged in to reply to this topic.