pyvista: Python does not respond after closing a plot

Hi, when I plot something with PyVista plotter using IPython, it shows the figure correctly and I can interact with it (like rotating), but when I close the plot Python does not respond anymore, the plot is completely frozen and I have to manually do a “force quit” of Python.

However, I do not encounter this problem when I run the script directly from the command line using the python -m command but I get an error message instead. Please find more details below.


To Reproduce

After cloning the PyVista repository from GitHub, running python -m pip install -e . and upgrading PyVista to the latest version (0.25.3 at this moment), I run an example which shows how to create a PolyData object (https://docs.pyvista.org/examples/00-load/create-poly.html) through IPython :

import numpy as np
import pyvista as pv

# mesh points
vertices = np.array([[0, 0, 0],
                     [1, 0, 0],
                     [1, 1, 0],
                     [0, 1, 0],
                     [0.5, 0.5, -1]])

# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3],  # square
                   [3, 0, 1, 4],     # triangle
                   [3, 1, 2, 4]])    # triangle

surf = pv.PolyData(vertices, faces)

# plot each face with a different color
surf.plot(scalars=np.arange(3), cpos=[-1, 1, 0.5])

You should observe that Python does not respond anymore when you try to close the figure.

As mentioned above, I do not encounter the problem when I run directly the script with the python -m command, but the command line displays

/usr/local/opt/python/bin/python3.7: Error while finding module specification for 'create-poly.py' (ModuleNotFoundError: __path__ attribute not found on 'create-poly' while trying to find 'create-poly.py')


System Information:

                OS : Darwin
            CPU(s) : 8
           Machine : x86_64
      Architecture : 64bit
       Environment : IPython
        GPU Vendor : ATI Technologies Inc.
      GPU Renderer : AMD Radeon Pro 580 OpenGL Engine
       GPU Version : 4.1 ATI-3.9.15

  Python 3.7.7 (default, Mar 30 2020, 10:31:28)  [Clang 11.0.3
  (clang-1103.0.32.29)]

           pyvista : 0.25.3
               vtk : 9.0.0
             numpy : 1.18.1
           imageio : 2.8.0
           appdirs : 1.4.3
            scooby : 0.5.5
            meshio : 4.0.15
        matplotlib : 3.1.2
           IPython : 7.11.1
             scipy : 1.4.1

Hope this can be fixed as soon as possible !

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Can you also try starting IPython with python -m IPython and running from there? There’s a small chance that your ipython andpython commands belong to different python environments, and this will help exclude this. (It’s far more likely that some magic that IPython uses crosses wires with plotting, but it’s better to be sure we’re looking at the same env)

@adeak I just tried what you suggested and it does not change anything, the problem persists.

Can you also try starting IPython with python -m IPython and running from there? There’s a small chance that your ipython andpython commands belong to different python environments, and this will help exclude this. (It’s far more likely that some magic that IPython uses crosses wires with plotting, but it’s better to be sure we’re looking at the same env)

Can you please clarify what you mean by

when I run the script directly from the command line using the python -m command

? Running python -m create-poly.py is not meant to work. As far as I know that syntax is only for executable packages with a __main__.py. (Detailed specs in PEP 338)

@adeak, I can confirm that running python -m create-poly.py displays the plot correctly (even if I get an error message when closing the figure).

@cverrier, can you try just: python create-poly.py

@banesullivan, without the -m flag, it just works perfectly (no error message at the end). I still do not understand what is going on when I run the script from IPython.

Can you please clarify what you mean by

when I run the script directly from the command line using the python -m command

? Running python -m create-poly.py is not meant to work. As far as I know that syntax is only for executable packages with a __main__.py. (Detailed specs in PEP 338)