Python Forum

Full Version: How to enable Matplotlib within virtual environment?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Cross posted from Linux Mint forum. So far I am unable to get Matplotlib to function inside the virtual environment; LMDE 6, AMD64.

Let's suppose there is the file '~/path/file.py', and there is the virtual environment 'vEnv'. The contents of file.py is:

import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',
       title='About as simple as it gets, folks')
ax.grid()

fig.savefig("test.png")
plt.show()
At Linux terminal there be a command, it gives error output:

Output:
(vEnv) user@host:~$ python3 -i ~/path/file.py
Error:
qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin. qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: vnc, vkkhrdisplay, wayland, offscreen, minimalegl, eglfs, linuxfb, xcb, minimal, wayland-egl. Aborted (core dumped)
Here is a summary of the virtual environment:

Output:
(vEnv) user@host:~$ python3 -m pip list -v Package Version Location Installer ------------------ ----------- -------------------------------------------- --------- certifi 2024.8.30 /home/user/vEnv/lib/python3.11/site-packages pip charset-normalizer 3.3.2 /home/user/vEnv/lib/python3.11/site-packages pip contourpy 1.3.0 /home/user/vEnv/lib/python3.11/site-packages pip cycler 0.12.1 /home/user/vEnv/lib/python3.11/site-packages pip fonttools 4.53.1 /home/user/vEnv/lib/python3.11/site-packages pip idna 3.10 /home/user/vEnv/lib/python3.11/site-packages pip kiwisolver 1.4.7 /home/user/vEnv/lib/python3.11/site-packages pip lorem 0.1.1 /home/user/vEnv/lib/python3.11/site-packages pip matplotlib 3.9.2 /home/user/vEnv/lib/python3.11/site-packages pip meson 1.5.0 /home/user/vEnv/lib/python3.11/site-packages pip mpmath 1.3.0 /home/user/vEnv/lib/python3.11/site-packages pip numpy 2.1.0 /home/user/vEnv/lib/python3.11/site-packages pip packaging 24.1 /home/user/vEnv/lib/python3.11/site-packages pip pandas 2.2.3 /home/user/vEnv/lib/python3.11/site-packages pip pillow 10.4.0 /home/user/vEnv/lib/python3.11/site-packages pip pip 23.0.1 /home/user/vEnv/lib/python3.11/site-packages pip platformdirs 4.3.6 /home/user/vEnv/lib/python3.11/site-packages pip pooch 1.8.2 /home/user/vEnv/lib/python3.11/site-packages pip pyparsing 3.1.4 /home/user/vEnv/lib/python3.11/site-packages pip PyQt6 6.7.1 /home/user/vEnv/lib/python3.11/site-packages pip PyQt6-Qt6 6.7.3 /home/user/vEnv/lib/python3.11/site-packages pip PyQt6_sip 13.8.0 /home/user/vEnv/lib/python3.11/site-packages pip python-dateutil 2.9.0.post0 /home/user/vEnv/lib/python3.11/site-packages pip pytz 2024.2 /home/user/vEnv/lib/python3.11/site-packages pip pyvista 0.44.1 /home/user/vEnv/lib/python3.11/site-packages pip requests 2.32.3 /home/user/vEnv/lib/python3.11/site-packages pip scooby 0.10.0 /home/user/vEnv/lib/python3.11/site-packages pip setuptools 66.1.1 /home/user/vEnv/lib/python3.11/site-packages pip six 1.16.0 /home/user/vEnv/lib/python3.11/site-packages pip sympy 1.13.3 /home/user/vEnv/lib/python3.11/site-packages pip typing_extensions 4.12.2 /home/user/vEnv/lib/python3.11/site-packages pip tzdata 2024.2 /home/user/vEnv/lib/python3.11/site-packages pip urllib3 2.2.3 /home/user/vEnv/lib/python3.11/site-packages pip vtk 9.3.1 /home/user/vEnv/lib/python3.11/site-packages pip
My question is: what is a good and simple way to get Matplotlib functionality within said virtual environment?
How can I diagnose the specific error message I receive when trying to execute the script in the terminal, and what common issues should I look for?