簡體   English   中英

如何修復 PyQT6/PySide6 在使用 tox 時拋出 `qt.qpa.xcb: could not connect to display`?

[英]How do I fix PyQT6/PySide6 throwing the `qt.qpa.xcb: could not connect to display` when using tox?

我正在嘗試使用 pytest 為 PySide6 應用程序編寫測試。我還使用 tox 來運行這些測試; 但是,我遇到了一個問題。 在測試期間,每次測試都失敗並顯示 output:

tests/test_application.py::test_application_startup qt.qpa.xcb: could not connect to display 
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, minimalegl, wayland-egl, wayland, vkkhrdisplay, offscreen, linuxfb, vnc, minimal, xcb.

Fatal Python error: Aborted

<Stacktrace omitted due to SO believing it to be spam, sorry :(>

Extension modules: xxsubtype, shiboken6.Shiboken, PySide6.QtCore, PySide6.QtGui, PySide6.QtWidgets, PySide6.QtTest, PySide6.QtUiTools, markupsafe._speedups (total: 8)
Aborted (core dumped)

這是我的毒性配置:

[tox]
minversion = 3.24
envlist =
    py310
isolated_build = True

[testenv]
description = Invoke pytest to run automated tests
setenv =
    TOXINIDIR = {toxinidir}
passenv =
    HOME
    SETUPTOOLS_*
    PYTHONPATH
deps =
    PySide6==6.4.1
    qt-material==2.12
    setuptools
    coverage
    pytest
    pytest-qt
commands =
    coverage run --context={envname} -m pytest --strict-markers --strict-config --tb=short --verbose --capture=no --full-trace
parallel_show_output = True

我的環境:Ubuntu 20.04 Python 3.10.8 tox==3.27.1

失敗的測試代碼:

from PySide6.QtWidgets import QApplication

def test_application_startup() -> None:
    """Ensure the application builds and configures."""
    # Run the application
    QApplication(sys.argv)

請注意,我的環境中也安裝了tox-conda ,但是,即使沒有它,我也可以顯示此問題。

由於我正在運行 Miniconda,因此我考慮使用它而不是 pip 安裝 PySide6,但沒有成功。 在終端的 tox 配置中運行命令會成功,因此我相信我的系統已准備就緒。 這只是因為有毒而失敗,而且只有毒。

tox 提供隔離,這也意味着環境變量不會自動傳入。

我沒有使用 PyQT6 的經驗,所以我不知道具體的環境變量,但你可以嘗試允許所有變量作為啟動器。

passenv = *

如果這可行,您可以閱讀更多關於 PyQT6 的信息並找出哪些環境變量是必需的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM