问题
I am trying to control Paraview interactively using IDLE. This would involve sending commands from IDLE and seeing the changes occur in Paraview. I would rather not use the in-Paraview python shell.
So far, I have succeeded in importing the Paraview modules (simple, servermanager…etc) from IDLE. However the commands sent do not reflect in Paraview. For instance:
>>> from paraview.simple import *
>>> cone = Cone()
>>> Show()
>>> Render()
does indeed create a cone. However the cone is output to a new, independent OpenGL window, and not the Paraview GUI.
Is it possible to control Paraview interactively using IDLE? If so how to accomplish this? Thanks
回答1:
You need to run paraview in multiclient/server mode. In a terminal run pvserver.
./bin/pvserver --multi-clients
In another terminal, run paraview and connect to your server
./bin/paraview
File->Connect
AddServer -> Choose a name -> Configure -> Save
Connect
In a third terminal, run pvpython (or your own configured python)
./bin/pvpython
>> from paraview.simple import *
>> Connect("localhost")
>> Cone()
>> Show()
回答2:
I built paraview against my system python so that I could use ipython
and other packages. I just had to set my PYTHONPATH
to point to the paraview python site packages and the LD_LIBRARY_PATH
to point to the paraview lib directory.
export PYTHONPATH=/path/to/paraview/install/lib/python2.7/site-packages
export LD_LIBRARY_PATH=/path/to/paraview/install/lib
$ ipython
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from paraview.simple import *
In [2]: Connect("localhost")
Out[2]: Connection (cs://localhost:11111) [2]
In [3]: Cone()
Out[3]: <paraview.servermanager.Cone at 0x7f30716cde10>
In [4]: Show()
Out[4]: <paraview.servermanager.GeometryRepresentation at 0x7f307167b210>
In [5]: GetSources()
Out[5]: {('Cone1', '8803'): <paraview.servermanager.Cone at 0x7f30716cde10>}
In [6]: GetActiveSource()
Out[6]: <paraview.servermanager.Cone at 0x7f30716cde10>
Screen shot of the rendered cone from the ipython paraview client
My paraview version was built from master on Ubuntu 18.04.
The only issue I had was a missing __init__.py
file in the python site-packages/paraview/modules
directory.
In [1]: from paraview.simple import *
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-cc11d49fb28b> in <module>()
----> 1 from paraview.simple import *
/home/dustin/repos/paraview_builds/master/install/lib/python2.7/site-packages/paraview/simple.py in <module>()
39
40 import paraview
---> 41 from paraview import servermanager
42 import paraview._backwardscompatibilityhelper
43
/home/dustin/repos/paraview_builds/master/install/lib/python2.7/site-packages/paraview/servermanager.py in <module>()
54 from paraview import _backwardscompatibilityhelper as _bc
55
---> 56 from paraview.modules.vtkPVServerImplementationCore import *
57 from paraview.modules.vtkPVClientServerCoreCore import *
58 from paraview.modules.vtkPVServerManagerCore import *
ImportError: No module named modules.vtkPVServerImplementationCore
I got around this by just creating an __init__.py
file in the paraview/modules
directory:
touch /path/to/paraview/install/lib/python2.7/site-packages/paraview/modules/__init__.py
来源:https://stackoverflow.com/questions/45236721/controlling-paraview-gui-from-python-idle