Problem about pyvista

Dear Fenicsx community
I have installed Fenicsx with WSL2 on windows and give a try to the demo “demo_poisson.py”.
I have obtained the output file with xdmf outputs too which shows everything went smooth. However, I got warnings about pyvista and had no interactive plots of the solution after compilation.
Can someone give me a clue?
Thanks

Pyvista requires an x-server (frame-buffer) to plot when running python scripts. This is not activated by default on windows, see: How to use GUI apps in WSL2 (forwarding X server) | Aitor Alonso (aalonso.dev)
You can either

  1. Follow the instructions above to get an x-server to render the GUI of pyvista
  2. Set environment variable PYVISTA_OFF_SCREEN=true. Start a virtual frame-buffer prior to plotting (pyvista.start_xvfb()), Add a plotter.screenshot("figure.png") instead of the plotter.show(). This will save a png of the figure.

For the record, my student installed WSL2, installed pyvista (and scooby) via pip. It worked (displayed plots) without further configuration. I don’t know why it worked in our case but doesn’t work in others, sorry! dokken’s links will be useful.

One suggestion for debugging is to check basic matplotlib functionality. Does matplotlib give the same error? e.g.

python3 -c "import matplotlib.pyplot as plt; import numpy; x=numpy.linspace(0,10,100); plt.plot(x,x); plt.show()"

Does matplotlib display the simple plot?

In regards to the WSL2 environment, it installs Ubuntu. Always use the ubuntu packages where possible, and don’t use pip to install packages. e.g. install matplotlib via

apt-get install python3-matplotlib

I mention this in case the reason pyvista (or matplotlib) worked for us and not for you is if you used pip instead of apt to install matplotlib. You can check which matploblib you’re using via python3 -c "import matplotlib; print(matplotlib.__path__)"

The situation is more complicated then we’d like it to be since ubuntu does not have its own pyvista package available yet (a request to make it available was made in Debian Bug#1001105). pip installation is a workaround which carries the danger of installing python packages with incompatibile library versions. The risk can be reduced by using the --no-deps option to only install the specified packages and not pull in other package dependencies.

pyvista requires numpy, imageio, pillow, appdirs and vtk, which are all available for ubuntu. It also requires scooby, which, like pyvista, is not yet available for ubuntu. Hence to get pyvista installed on an ubuntu/debian system (including the WSL2 environment), I recommend:

  1. check that numpy, imageio, pillow, appdirs and vtk have not been installed by pip
    – inspect the contents of ~/.local/lib/python3*/site-packages/
    – remove any unwanted packages (delete the directory, or use pip uninstall <package>)

  2. check that they have been installed by apt

apt-get install python3-numpy python3-imageio python3-pil python3-appdirs python3-vtk9

(you could use python3-vtk7 instead of python3-vtk9 if vtk9 is giving problems)

  1. install pyvista with
pip install --user --no-deps scooby pyvista
1 Like

Given the reference to start_xvfb, another possibility is that xvfb needs to be explicitly installed

apt-get install xvfb

Thanks a lot. Dr. Dokken’s suggestion worked out perfectly.

@dparsons is your student using Windows 11? I believe in this case WSL uses wslg that has xorg and Wayland servers preconfigured. The thing is that wslg is not available on windows 10, which many people still use, hence the need for additional configuration.

Thanks @Calva, that does sound right. My student is using Windows 11. Your explanation makes sense then: WSL2 and pyvista can be expected to work smoothly on Windows 11 (via wslg) but will need the extra configuration on Windows 10.