Issue with wayland display on Debian

When I try to draw a plot using matplotlib I get this error:

Error: Can't open display: wayland-0

which I also get when I try to use xclip (if I log in with X11 it works fine).

When I run kinfo I get this:

> kinfo
Operating System: Debian GNU/Linux 12
KDE Plasma Version: 5.27.5
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 6.1.0-29-amd64 (64-bit)
Graphics Platform: offscreen
Processors: 4 × Intel® Core™ i5-6200U CPU @ 2.30GHz
Memory: 7.6 GiB of RAM
Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize 8, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile) 
23 -- exe=/usr/bin/kcmshell5
19 -- platform=offscreen
18 -- appname=kcmshell5
17 -- apppath=/usr/bin
9 -- signal=6
9 -- pid=7998
18 -- appversion=5.27.5
35 -- programname=System Settings Module
31 -- bugaddress=submit@bugs.kde.org
KCrash: crashing... crashRecursionCounter = 2
KCrash: Application Name = kcmshell5 path = /usr/bin pid = 7998
KCrash: Arguments: /usr/bin/kcmshell5 kcm_about-distro --args dump 
KCrash: Attempting to start /usr/lib/x86_64-linux-gnu/libexec/drkonqi
[1]  + 7998 suspended (signal)  kinfo

Hi! Some folks here might be happen to be familiar with matplotlib, but I would definitely also suggest checking around whatever community forums exist (possibly https://discourse.matplotlib.org) for that particular software.

xclip is built specifically for X11 desktop sessions, so I’d think it would either be extremely limited, or not function at all, in a Wayland desktop session.

Just to check, are you running into any issues specific to KDE software?

Given that the setup involved xclip the other components might be assuming availability of an X11 connection as well.

Your kinfo output suggests that it could either not find either an X11 or Wayland connection (or failed to load the respective plugins) so it fell back to offscreen.

You could try starting an explicit XWayland session in your console and then run your workflow through that.

For a native Wayland based workflow you’ll need to check that each component is compatible and setup correctly (might need config, command line arguments, or environment variables)

I found out that the issue was with the terminal, before installing KDE I tried MATE, then I switched to KDE but was still using MATE terminal. Both the plots with matplotlib and the xclip command work fine when I run them from Konsole. Probably because of different env variable settings?

Yes, possible.

Maybe this approach allows KWin to detect that it needs an XWayland session and starts that up for the tools to connect to and work as expected.