Python在NixOS(Sway)上查找Qt平台插件的问题

问题描述 投票:0回答:1

我最近转移到 NixOS,我正在启动的 python 项目遇到问题。 我决定继续使用 Conda 来处理基于 NixOS wiki 的 python 环境。我正在运行 NixOS,并使用 Sway (wayland) 作为我的窗口管理器。当我尝试使用此代码生成图形时:

import matplotlib.pyplot as plt
fig = plt.figure()

我收到以下错误:

qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
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: eglfs, minimal, minimalegl, offscreen, vnc, webgl, xcb.

Aborted (core dumped)

我在网上搜索了一下,发现了几个类似的问题,但我太天真了,不明白我哪里出了问题。例如,同样的问题被引用到HERE,但我不够精明,无法跟踪讨论。这个问题也在 NixOS Discourse 页面 上进行了讨论。 我不记得从哪个论坛找到这个建议,但像这样调整脚本:

import matplotlib.pyplot as plt
import os
os.environ['QT_QPA_PLATFORM'] = "wayland"
fig = plt.figure()

至少解决了“xcb”错误。所以我只剩下:

qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, minimal, minimalegl, offscreen, vnc, webgl, xcb.

Aborted (core dumped)

我不知道我是否缺少包/库,是否是我的

conda
环境的问题,是否是 NixOS 的问题?谢谢你帮助我摆脱我的天真。干杯!

python matplotlib nixos wayland
1个回答
0
投票

来自 NixOS github 页面,添加:

import matplotlib
matplotlib.use("TkAgg")

解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.