Cannot use pyvista in conda

Hi all,
Trying to use pyvista to visualise functions in dolfinx.
I’m in a clean conda environment built with:

conda create -n my_env
conda activate my_env
conda install -c conda-forge fenics-dolfinx mpich pyvista

as indicated in the instructions.

I obtain this error when trying to call pyvista:

[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 4 Illegal instruction: Likely due to memory corruption
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind and https://petsc.org/release/faq/
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run 
[0]PETSC ERROR: to get more information on the crash.
Abort(59) on node 0 (rank 0 in comm 0): application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0

Generated with:

from dolfinx import mesh, fem, plot
from mpi4py import MPI

msh = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8)

V = fem.FunctionSpace(msh, ("CG", 1))
u = fem.Function(V)

import pyvista
pyvista.OFF_SCREEN = True

pyvista.start_xvfb()

u_topology, u_cell_types, u_geometry = plot.vtk_mesh(V)
u_grid = pyvista.UnstructuredGrid(u_topology, u_cell_types, u_geometry)
u_grid.point_data["u"] = u.x.array.real
u_grid.set_active_scalars("u")
u_plotter = pyvista.Plotter()
u_plotter.add_mesh(u_grid, show_edges=False)
u_plotter.view_xy()
if not pyvista.OFF_SCREEN:
    u_plotter.show()
else:
    figure = u_plotter.screenshot("solution.png")

I remember having similar issues with packages installed with a mix of pip and conda, but here everything is installed via conda.

Any idea?
Thanks!!

I think this is a case of mixing matplotlib from pip or conda but not quite sure how to debug since it occurs even on a clean conda environment.

I tried pip uninstall matplotlib but still doesn’t work

You can use the following command at the terminal:
conda env list
to see if you do indeed have matplotlib pip installed, but I would suspect that the issue is the line
pyvista.start_xvfb()

I think I ran into some similar issues and I was able to just delete that line and get the script to run.

I’m not well versed in ‘virtual framebuilders’ (see pyvista documentation) but I believe this is related to running the script on a machine using virtual memory without have to show screen output. Sounds like this is more geared towards clusters, so you can do without on your own machine if you have a display output. Or you can make sure you go download libgl1-mesa-glx_xvfb

You will also need to change the line:
u_topology, u_cell_types, u_geometry = plot.vtk_mesh(V)
to
u_topology, u_cell_types, u_geometry = plot.create_vtk_mesh(V)

This is the command to show all the environment not showing the packages installed

Commenting this out didn’t help

This is the 0.7 syntax

sorry, I meant
conda list

Not sure what you are talking about, plot.create_vtk_mesh() is the syntax I’ve been using since at least version 0.5

What system are you running this on? It looks like you are having an issue similar to this.

I completely reinstalled anaconda and only installed dolfinx via the commands suggested.
I opened an issue on the conda-forge repo for dolfinx giving all the details of my env.

Well the syntax has changed :slight_smile:

Hi, today I set up a jupyterhub for fenicsx via anaconda and had initially also issues with pyvista. I however got it to work after installing xvfb on the host system via:

$ sudo apt install libgl1-mesa-glx xvfb

I also installed all kinds of xvfb packages via conda - to be honest I’m not sure what got it to work eventually. But here is my conda env:

_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
aiohttp                   3.8.6                    pypi_0    pypi
aiosignal                 1.3.1                    pypi_0    pypi
anyio                     4.0.0                    pypi_0    pypi
argon2-cffi               23.1.0                   pypi_0    pypi
argon2-cffi-bindings      21.2.0                   pypi_0    pypi
arrow                     1.3.0                    pypi_0    pypi
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
async-lru                 2.0.4                    pypi_0    pypi
async-timeout             4.0.3                    pypi_0    pypi
attrs                     23.1.0                   pypi_0    pypi
babel                     2.13.1                   pypi_0    pypi
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.5              pyhd8ed1ab_0    conda-forge
beautifulsoup4            4.12.2                   pypi_0    pypi
binutils_impl_linux-64    2.39                 he00db2b_1    conda-forge
binutils_linux-64         2.39                h5fc0e48_13    conda-forge
bleach                    6.1.0                    pypi_0    pypi
blosc                     1.21.5               h0f2a231_0    conda-forge
boost-cpp                 1.78.0               h2c5509c_4    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.20.1               hd590300_1    conda-forge
ca-certificates           2023.7.22            hbcca054_0    conda-forge
certifi                   2023.7.22                pypi_0    pypi
cffi                      1.16.0          py310h2fee648_0    conda-forge
charset-normalizer        3.3.1                    pypi_0    pypi
cmocean                   3.0.3                    pypi_0    pypi
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
colorcet                  3.0.1                    pypi_0    pypi
comm                      0.1.4              pyhd8ed1ab_0    conda-forge
debugpy                   1.8.0           py310hc6cd4ac_1    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1                    pypi_0    pypi
exceptiongroup            1.1.3              pyhd8ed1ab_0    conda-forge
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
fastjsonschema            2.18.1                   pypi_0    pypi
fenics-basix              0.5.1           py310hbf28c38_1    conda-forge
fenics-dolfinx            0.5.2           py310h7dda09f_102    conda-forge
fenics-ffcx               0.5.0              pyhb871ab6_1    conda-forge
fenics-libbasix           0.5.1                heb3b609_1    conda-forge
fenics-libdolfinx         0.5.2              hb062b81_102    conda-forge
fenics-ufcx               0.5.0                hb871ab6_1    conda-forge
fenics-ufl                2022.2.0           pyhd8ed1ab_0    conda-forge
fftw                      3.3.10          mpi_openmpi_h4a81ba8_8    conda-forge
fqdn                      1.5.1                    pypi_0    pypi
freetype                  2.12.1               h267a509_2    conda-forge
freetype-py               2.4.0                    pypi_0    pypi
frozenlist                1.4.0                    pypi_0    pypi
gcc_impl_linux-64         10.4.0              h5231bdf_19    conda-forge
gcc_linux-64              10.4.0              h9215b83_13    conda-forge
glx                       0.6                      pypi_0    pypi
gmp                       6.2.1                h58526e2_0    conda-forge
gxx_impl_linux-64         10.4.0              h5231bdf_19    conda-forge
gxx_linux-64              10.4.0              h6e491c6_13    conda-forge
hdf5                      1.12.2          mpi_openmpi_h41b9b70_1    conda-forge
hypre                     2.25.0          mpi_openmpi_ha709252_0    conda-forge
icu                       73.2                 h59595ed_0    conda-forge
idna                      3.4                      pypi_0    pypi
imageio                   2.31.6                   pypi_0    pypi
importlib-metadata        6.8.0              pyha770c72_0    conda-forge
importlib_metadata        6.8.0                hd8ed1ab_0    conda-forge
iniconfig                 2.0.0              pyhd8ed1ab_0    conda-forge
ipydatawidgets            4.3.5                    pypi_0    pypi
ipykernel                 6.26.0             pyhf8b6a83_0    conda-forge
ipython                   8.16.1             pyh0d859eb_0    conda-forge
ipywidgets                8.1.1                    pypi_0    pypi
isoduration               20.11.0                  pypi_0    pypi
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.2                    pypi_0    pypi
json5                     0.9.14                   pypi_0    pypi
jsonpointer               2.4                      pypi_0    pypi
jsonschema                4.19.1                   pypi_0    pypi
jsonschema-specifications 2023.7.1                 pypi_0    pypi
jupyter-events            0.8.0                    pypi_0    pypi
jupyter-lsp               2.2.0                    pypi_0    pypi
jupyter-server            2.9.1                    pypi_0    pypi
jupyter-server-proxy      4.1.0                    pypi_0    pypi
jupyter-server-terminals  0.4.4                    pypi_0    pypi
jupyter_client            8.5.0              pyhd8ed1ab_0    conda-forge
jupyter_core              5.4.0           py310hff52083_0    conda-forge
jupyterlab                4.0.7                    pypi_0    pypi
jupyterlab-pygments       0.2.2                    pypi_0    pypi
jupyterlab-server         2.25.0                   pypi_0    pypi
jupyterlab-widgets        3.0.9                    pypi_0    pypi
kernel-headers_linux-64   2.6.32              he073ed8_16    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.21.2               h659d440_0    conda-forge
lcms2                     2.15                 hb7c19ff_3    conda-forge
ld_impl_linux-64          2.39                 hcc3a1bd_1    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libadios2                 2.8.3           mpi_openmpi_h64021f3_5    conda-forge
libaec                    1.1.2                h59595ed_1    conda-forge
libblas                   3.9.0           19_linux64_openblas    conda-forge
libcblas                  3.9.0           19_linux64_openblas    conda-forge
libcurl                   8.4.0                hca28451_0    conda-forge
libdeflate                1.19                 hd590300_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-devel_linux-64     10.4.0              hd38fd1e_19    conda-forge
libgcc-ng                 13.2.0               h807b86a_2    conda-forge
libgfortran-ng            13.2.0               h69a702a_2    conda-forge
libgfortran5              13.2.0               ha4646dd_2    conda-forge
libgomp                   13.2.0               h807b86a_2    conda-forge
libhwloc                  2.9.3           default_h554bfaf_1009    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
libjpeg-turbo             3.0.0                hd590300_1    conda-forge
liblapack                 3.9.0           19_linux64_openblas    conda-forge
libnghttp2                1.55.1               h47da74e_0    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libopenblas               0.3.24          pthreads_h413a1c8_0    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
libsanitizer              10.4.0              h5246dfb_19    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libsqlite                 3.43.2               h2797004_0    conda-forge
libssh2                   1.11.0               h0841786_0    conda-forge
libstdcxx-devel_linux-64  10.4.0              hd38fd1e_19    conda-forge
libstdcxx-ng              13.2.0               h7e041cc_2    conda-forge
libtiff                   4.6.0                ha9c0a0a_2    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libwebp-base              1.3.2                hd590300_0    conda-forge
libxcb                    1.15                 h0b41bf4_0    conda-forge
libxml2                   2.11.5               h232c23b_1    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
mako                      1.2.4                    pypi_0    pypi
markdown-it-py            3.0.0                    pypi_0    pypi
markupsafe                2.1.3                    pypi_0    pypi
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mdurl                     0.1.2                    pypi_0    pypi
meshio                    5.3.4                    pypi_0    pypi
metis                     5.1.0             h59595ed_1007    conda-forge
mistune                   3.0.2                    pypi_0    pypi
mpfr                      4.2.1                h9458935_0    conda-forge
mpi                       1.0                     openmpi    conda-forge
mpi4py                    3.1.5           py310h2a790f2_0    conda-forge
multidict                 6.0.4                    pypi_0    pypi
mumps-include             5.2.1               ha770c72_11    conda-forge
mumps-mpi                 5.2.1               hfb3545b_11    conda-forge
nbclient                  0.8.0                    pypi_0    pypi
nbconvert                 7.9.2                    pypi_0    pypi
nbformat                  5.9.2                    pypi_0    pypi
ncurses                   6.4                  hcb278e6_0    conda-forge
nest-asyncio              1.5.8              pyhd8ed1ab_0    conda-forge
nose                      1.3.7                    pypi_0    pypi
nose-xvfb                 0.13.1                   pypi_0    pypi
notebook-shim             0.2.3                    pypi_0    pypi
numpy                     1.26.0          py310hb13e2d6_0    conda-forge
openjpeg                  2.5.0                h488ebb8_3    conda-forge
openmpi                   4.1.6              hc5af2df_101    conda-forge
openssl                   3.1.4                hd590300_0    conda-forge
overrides                 7.4.0                    pypi_0    pypi
packaging                 23.2               pyhd8ed1ab_0    conda-forge
pandocfilters             1.5.0                    pypi_0    pypi
param                     2.0.0                    pypi_0    pypi
parmetis                  4.0.3             he9a3056_1005    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
petsc                     3.17.4          real_h4502189_101    conda-forge
petsc4py                  3.17.4          real_h5540cce_101    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.0.1                   pypi_0    pypi
pip                       23.3.1             pyhd8ed1ab_0    conda-forge
pixman-cos6-x86_64        0.32.8            h9b0a68f_1105    conda-forge
platformdirs              3.11.0             pyhd8ed1ab_0    conda-forge
pluggy                    1.3.0              pyhd8ed1ab_0    conda-forge
pooch                     1.8.0                    pypi_0    pypi
prometheus-client         0.17.1                   pypi_0    pypi
prompt-toolkit            3.0.39             pyha770c72_0    conda-forge
prompt_toolkit            3.0.39               hd8ed1ab_0    conda-forge
psutil                    5.9.5           py310h2372a71_1    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptscotch                  6.0.9                h0a9c416_2    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pugixml                   1.11.4               h59595ed_1    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyct                      0.5.0                    pypi_0    pypi
pygments                  2.16.1             pyhd8ed1ab_0    conda-forge
pyopengl                  3.1.7                    pypi_0    pypi
pytest                    7.4.3              pyhd8ed1ab_0    conda-forge
pytest-xvfb               3.0.0              pyhd8ed1ab_0    conda-forge
python                    3.10.13         hd12c33a_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-json-logger        2.0.7                    pypi_0    pypi
python_abi                3.10                    4_cp310    conda-forge
pythreejs                 2.4.2                    pypi_0    pypi
pyvirtualdisplay          3.0             py310hff52083_3    conda-forge
pyvista                   0.42.3                   pypi_0    pypi
pyyaml                    6.0.1                    pypi_0    pypi
pyzmq                     25.1.1          py310h795f18f_2    conda-forge
readline                  8.2                  h8228510_1    conda-forge
rectangle                 0.4                      pypi_0    pypi
referencing               0.30.2                   pypi_0    pypi
requests                  2.31.0                   pypi_0    pypi
rfc3339-validator         0.1.4                    pypi_0    pypi
rfc3986-validator         0.1.1                    pypi_0    pypi
rich                      13.6.0                   pypi_0    pypi
rpds-py                   0.10.6                   pypi_0    pypi
scalapack                 2.2.0                h67de57e_1    conda-forge
scooby                    0.9.2                    pypi_0    pypi
scotch                    6.0.9                hb2e6521_2    conda-forge
send2trash                1.8.2                    pypi_0    pypi
setuptools                68.2.2             pyhd8ed1ab_0    conda-forge
simpervisor               1.0.0                    pypi_0    pypi
six                       1.16.0             pyh6c4a22f_0    conda-forge
slepc                     3.17.2          real_h624bf36_100    conda-forge
slepc4py                  3.17.2          real_h024a88e_101    conda-forge
snappy                    1.1.10               h9fff704_0    conda-forge
sniffio                   1.3.0                    pypi_0    pypi
soupsieve                 2.5                      pypi_0    pypi
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
suitesparse               5.10.1               h9e50725_1    conda-forge
superlu                   5.2.2                h00795ac_0    conda-forge
superlu_dist              7.2.0                h34f6f4d_0    conda-forge
sysroot_linux-64          2.12                he073ed8_16    conda-forge
tbb                       2021.10.0            h00ab1b0_2    conda-forge
terminado                 0.17.1                   pypi_0    pypi
tinycss2                  1.2.1                    pypi_0    pypi
tk                        8.6.13               h2797004_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tornado                   6.3.3           py310h2372a71_1    conda-forge
traitlets                 5.12.0             pyhd8ed1ab_0    conda-forge
traittypes                0.2.1                    pypi_0    pypi
trame                     3.2.8                    pypi_0    pypi
trame-client              2.12.6                   pypi_0    pypi
trame-components          2.2.1                    pypi_0    pypi
trame-server              2.12.0                   pypi_0    pypi
trame-vtk                 2.5.9                    pypi_0    pypi
trame-vuetify             2.3.1                    pypi_0    pypi
types-python-dateutil     2.8.19.14                pypi_0    pypi
typing-extensions         4.8.0                hd8ed1ab_0    conda-forge
typing_extensions         4.8.0              pyha770c72_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
uri-template              1.3.0                    pypi_0    pypi
urllib3                   2.0.7                    pypi_0    pypi
vtk                       9.2.6                    pypi_0    pypi
wcwidth                   0.2.8              pyhd8ed1ab_0    conda-forge
webcolors                 1.13                     pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
websocket-client          1.6.4                    pypi_0    pypi
wheel                     0.41.2             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.9                    pypi_0    pypi
wslink                    1.12.4                   pypi_0    pypi
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-x11-server-common-cos6-x86_64 1.17.4            h9b0a68f_1105    conda-forge
xorg-x11-server-xvfb-cos6-x86_64 1.17.4            h9b0a68f_1105    conda-forge
xtensor                   0.24.7               h00ab1b0_0    conda-forge
xtl                       0.7.5                hf52228f_0    conda-forge
xvfbwrapper               0.2.9                    pypi_0    pypi
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
yarl                      1.9.2                    pypi_0    pypi
zeromq                    4.3.5                h59595ed_0    conda-forge
zfp                       0.5.5                h9c3ff4c_8    conda-forge
zipp                      3.17.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               hd590300_5    conda-forge
zstd                      1.5.5                hfc55251_0    conda-forge

Note that I use the fenicx version 0.5.2. Here is a working example of how I use it (and it works for me):

import pyvista
pyvista.start_xvfb()
pyvista.set_jupyter_backend("static") # change to "server" for interactive output
grid = pyvista.UnstructuredGrid(*plot.create_vtk_mesh(V))
grid.point_data["c"] = c_n.x.array.real
grid.set_active_scalars("c")
plotter = pyvista.Plotter()
plotter.add_mesh(grid, clim=[0, 1], show_edges=True, show_scalar_bar=True)
plotter.view_xy()
figure = plotter.screenshot("initial.png")
if not pyvista.OFF_SCREEN:
    plotter.show()
else:
    figure = plotter.screenshot("initial.png")
1 Like