无法在Paraview中导入matplotlib

时间:2017-04-05 06:52:10

标签: python matplotlib python-import paraview

我正在尝试使用用户手册第73页讨论的Paraview中的matplotlib来制作图形。我在Windows 10上运行Paraview 5.2.0 64位。最小的例子是:

def setup_data(view):
    pass

def render(view, width, height):
    from paraview import python_view
    figure = python_view.matplotlib_figure(width, height)
    ax = figure.add_subplot(1,1,1)
    return python_view.figure_to_image(figure)

然而,这导致Python视图中出现黑屏,输出窗口出现以下错误:

  

错误:无法导入matplotlib.backends.backend_agg.FigureCanvasAgg

     

错误:无法导入matplotlib.figure.Figure

如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

在我的情况下,事实证明matplotlib在导入agg后端时无法导入dateutil模块时无法加载。运行pvpython并专门从matplotlib导入agg后端产生:

>>> import matplotlib.backends.backend_agg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\backends\backend_agg.py", line 31, in <module>
    from matplotlib.figure import Figure
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\figure.py", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\axes.py", line 19, in <module>
    import matplotlib.dates as mdates
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\dates.py", line 119, in <module>
    from dateutil.rrule import rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, \
ImportError: No module named dateutil.rrule

具体导入dateutil表示未安装:

>>> import dateutil
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named dateutil

不幸的是,我的pvpython运行版本2.7.3,因此默认情况下未安装pip,我发现在Windows 10中pip安装pvpython很困难。 ,我下载了python-dateutil 2.6.0并从zip存档中只提取了文件夹dateutil到位于以下位置的pvpython库文件夹:

C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\

重新启动Paraview然后在Python视图中给了我一个数字而不是黑屏。