【问题标题】:Controlling Paraview GUI from Python IDLE从 Python IDLE 控制 Paraview GUI
【发布时间】:2017-07-21 11:38:17
【问题描述】:

我正在尝试使用 IDLE 以交互方式控制 Paraview。这将涉及从 IDLE 发送命令并查看 Paraview 中发生的更改。我宁愿不使用 in-Paraview python shell。

到目前为止,我已经成功地从 IDLE 导入了 Paraview 模块(simple、servermanager…等)。但是,发送的命令不会反映在 Paraview 中。例如:

>>> from paraview.simple import *
>>> cone = Cone()
>>> Show()
>>> Render()

确实创建了一个圆锥体。然而,锥体被输出到一个新的、独立的 OpenGL 窗口,而不是 Paraview GUI。

是否可以使用 IDLE 以交互方式控制 Paraview?如果是这样如何做到这一点?谢谢

【问题讨论】:

  • IDLE 具有简化 tkinter 应用程序开发的特殊功能。它对其他任何事情都没有做任何特别的事情。对于纯交互式控制,您应该与控制台中的交互式 Python 一样好。 (IDLE 确实增加了编写和快速运行保存脚本的能力。)我很困惑你不想使用 Paraview 的控制台?他们把它弄残了吗?否则,它应该和 Python 或 IDLE 的 shell 一样好。
  • 我不想使用 Paraview 的控制台,因为 Paraview 只是我使用 Python 同时控制的多个应用程序之一。将我的工作集中在 Paraview 的 shell 中并开始编写与 Paraview 无关的东西是没有意义的。基本上我可能会从另一个应用程序的 python API 中获取数据,使用 numpy 或 matlab python 引擎对其进行处理,然后仅在 Paraview 中将其输出用于可视化/动画目的。请参阅 Paraview 只是该过程中的一小步。我不希望它接管我的工作,这实质上涉及其他应用程序
  • 这是有道理的,但在不了解 Paraview 的情况下,我无法进一步评论。看看你能不能找到专门的 Paraview 支持列表之类的。

标签: python python-2.7 python-idle paraview


【解决方案1】:

您需要在多客户端/服务器模式下运行 paraview。 在终端中运行 pvserver。

./bin/pvserver --multi-clients

在另一个终端中,运行 paraview 并连接到您的服务器

./bin/paraview
File->Connect
AddServer -> Choose a name -> Configure -> Save
Connect

在第三个终端中,运行 pvpython(或您自己配置的 python)

./bin/pvpython
>> from paraview.simple import *
>> Connect("localhost")
>> Cone()
>> Show()

【讨论】:

  • 首先我认为Connect(localhost)应该改为Connect("localhost")以避免NameError: name 'localhost' is not defined错误。其次,当运行Show() 时,它返回一个错误RuntimeError: Show() needs a proxy argument or that an active source is set. 加上 ParaView,在所有这些之后打开没有响应。
  • 确实,你需要先创建一个源。我已经更新了我的答案。
  • 这是与 paraview 交互的好方法!我想知道您是否可以将此添加到this documentation
  • 这与 ParaView 指南 imo 更相关。
【解决方案2】:

我针对我的系统 python 构建了 paraview,以便我可以使用 ipython 和其他包。我只需将PYTHONPATH 设置为指向paraview python 站点包,将LD_LIBRARY_PATH 设置为指向paraview lib 目录。

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

我的 paraview 版本是在 Ubuntu 18.04 上从 master 构建的。

我遇到的唯一问题是 python 站点-packages/paraview/modules 目录中缺少 __init__.py 文件。

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

我只是通过在paraview/modules 目录中创建一个__init__.py 文件来解决这个问题:

touch /path/to/paraview/install/lib/python2.7/site-packages/paraview/modules/__init__.py

【讨论】:

    猜你喜欢
    • 2014-09-30
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多