Home › Forum › SOFA › Using SOFA › [SOLVED] Error when running scene in python interpreter with SofaPython3 plugin
Tagged: 64_bits, Linux_ubuntu, Plugin_other, SOFA_other
- This topic has 9 replies, 2 voices, and was last updated 4 years, 9 months ago by timp.
-
AuthorPosts
-
20 March 2020 at 17:13 #15512timpBlocked
Hi all,
I just installed the SofaPython3 plugin (SP3) with out-of-tree builds following the instructions posted here:
https://github.com/SofaDefrost/plugin.SofaPython3/issues/137
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:40 #15522jnbrunetModeratorHi @Tim,
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()
or
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()
or
3. Use the AddPluginRepository component in your scene
<AddPluginRepository path="/home/tim/sofa/build/lib" />
23 March 2020 at 10:19 #15523timpBlockedHi @jnbrunet,
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:08 #15526timpBlockedHi @jnbrunet,
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:33 #15531jnbrunetModeratorHey @timp
My mistake, it is
from Sofa import Simulation
, and notfrom 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:49 #15538timpBlockedHey @jnbrunet,
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:54 #15539jnbrunetModeratorDid 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.txt
24 March 2020 at 12:13 #15540timpBlockedHi @jnbrunet,
The output is
SOFAGUI_QGLVIEWER:BOOL=ON SOFAGUI_QTVIEWER:BOOL=ON
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:20 #15560jnbrunetModeratorHi @timp,
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.ListSupportedGUI
returned 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 09:58 #15567 -
AuthorPosts
- You must be logged in to reply to this topic.