opencv 警告:忽略Gnome上的XDG_SESSION_TYPE=wayland,仍使用QT_QPA_PLATFORM=wayland在Wayland上运行

x4shl7ld  于 2023-01-26  发布在  其他
关注(0)|答案(2)|浏览(1151)

我尝试使用库cv2来改变图片。在调试模式中我发现函数cv2.namedWindow存在问题:

def run(self):
    name_of_window = 'Test_version'
    image_cv2 = cv2.imread('external_data/probe.jpg')
    cv2.namedWindow(name_of_window, cv2.WINDOW_NORMAL)
    cv2.imshow(name_of_window, image_cv2)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

在cv2.namedWindow出现警告和程序停止后,如果有人给予我建议,我会很高兴的。
当我调用os.environ时,显示如下:

environ({
            'PATH': '/home/spartak/PycharmProjects/python_base/lesson_016/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin',
            'LC_MEASUREMENT': 'ru_RU.UTF-8', 'XAUTHORITY': '/run/user/1000/.mutter-Xwaylandauth.MJ52B1',
            'INVOCATION_ID': 'dd129fae7f7c452cb8fa8cd53b9da873', 'XMODIFIERS': '@im=ibus',
            'LC_TELEPHONE': 'ru_RU.UTF-8',
            'XDG_DATA_DIRS': '/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop',
            'GDMSESSION': 'ubuntu', 'LC_TIME': 'ru_RU.UTF-8', 'SNAP_COMMON': '/var/snap/pycharm-community/common',
            'SNAP_INSTANCE_KEY': '', 'SNAP_USER_COMMON': '/home/spartak/snap/pycharm-community/common',
            'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus',
            'IDE_PROJECT_ROOTS': '/home/spartak/PycharmProjects/python_base', 'PS1': '(env) ', 'SNAP_REVISION': '256',
            'XDG_CURRENT_DESKTOP': 'ubuntu:GNOME', 'JOURNAL_STREAM': '8:37824', 'LC_PAPER': 'ru_RU.UTF-8',
            'SESSION_MANAGER': 'local/spartak-pc:@/tmp/.ICE-unix/2082,unix/spartak-pc:/tmp/.ICE-unix/2082',
            'USERNAME': 'spartak', 'LOGNAME': 'spartak', 'PWD': '/home/spartak/PycharmProjects/python_base/lesson_016',
            'MANAGERPID': '1951', 'IM_CONFIG_PHASE': '1', 'PYCHARM_HOSTED': '1', 'GJS_DEBUG_TOPICS': 'JS ERROR;JS LOG',
            'PYTHONPATH': '/home/spartak/PycharmProjects/python_base:/home/spartak/PycharmProjects/python_base/lesson_012/python_snippets:/home/spartak/PycharmProjects/python_base/chatbot:/snap/pycharm-community/256/plugins/python-ce/helpers/third_party/thriftpy:/snap/pycharm-community/256/plugins/python-ce/helpers/pydev:/home/spartak/.cache/JetBrains/PyCharmCE2021.2/cythonExtensions:/home/spartak/PycharmProjects/python_base/lesson_016',
            'SHELL': '/bin/bash', 'LC_ADDRESS': 'ru_RU.UTF-8',
            'GIO_LAUNCHED_DESKTOP_FILE': '/var/lib/snapd/desktop/applications/pycharm-community_pycharm-community.desktop',
            'BAMF_DESKTOP_FILE_HINT': '/var/lib/snapd/desktop/applications/pycharm-community_pycharm-community.desktop',
            'IPYTHONENABLE': 'True', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'GTK_MODULES': 'gail:atk-bridge',
            'VIRTUAL_ENV': '/home/spartak/PycharmProjects/python_base/lesson_016/env', 'SNAP_ARCH': 'amd64',
            'SYSTEMD_EXEC_PID': '2099', 'XDG_SESSION_DESKTOP': 'ubuntu', 'GNOME_SETUP_DISPLAY': ':1',
            'SNAP_LIBRARY_PATH': '/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void',
            'SSH_AGENT_LAUNCHER': 'gnome-keyring', 'SHLVL': '0', 'LC_IDENTIFICATION': 'ru_RU.UTF-8',
            'LC_MONETARY': 'ru_RU.UTF-8', 'SNAP_NAME': 'pycharm-community', 'QT_IM_MODULE': 'ibus',
            'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/etc/xdg', 'LANG': 'en_US.UTF-8',
            'SNAP_INSTANCE_NAME': 'pycharm-community', 'XDG_SESSION_TYPE': 'wayland',
            'SNAP_USER_DATA': '/home/spartak/snap/pycharm-community/256', 'PYDEVD_LOAD_VALUES_ASYNC': 'True',
            'DISPLAY': ':0', 'SNAP_REEXEC': '', 'WAYLAND_DISPLAY': 'wayland-0',
            'LIBRARY_ROOTS': '/home/spartak/.pyenv/versions/3.9.7/lib/python3.9:/home/spartak/.pyenv/versions/3.9.7/lib/python3.9/lib-dynload:/home/spartak/PycharmProjects/python_base/lesson_016/env/lib/python3.9/site-packages:/home/spartak/.cache/JetBrains/PyCharmCE2021.2/python_stubs/-1475777083:/snap/pycharm-community/256/plugins/python-ce/helpers/python-skeletons:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stdlib:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/jwt:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/six:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/mock:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/nmap:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/annoy:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/attrs:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/polib:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/retry:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/docopt:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/enum34:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/orjson:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/pysftp:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/xxhash:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/chardet:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/futures:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/pyaudio:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/tzlocal:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/Markdown:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/Werkzeug:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/aiofiles:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/colorama:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/filelock:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/paramiko:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/pathlib2:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/requests:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/waitress:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/freezegun:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/ipaddress:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/pyRFC3339:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/typed-ast:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/Deprecated:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/cachetools:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/frozendict:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/pyfarmhash:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/JACK-Client:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/contextvars:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/atomicwrites:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/cryptography:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/DateTimeRange:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/click-spinner:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/pkg_resources:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/python-gflags:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/python-slugify:/snap/pycharm-community/256/plugins/python-ce/helpers/typeshed/stubs/python-dateutil',
            'SNAP_VERSION': '2021.2.3', 'LC_NAME': 'ru_RU.UTF-8', 'XDG_SESSION_CLASS': 'user',
            '_': '/usr/bin/gnome-session', 'SNAP_DATA': '/var/snap/pycharm-community/256', 'PYTHONIOENCODING': 'UTF-8',
            'DESKTOP_SESSION': 'ubuntu', 'SNAP': '/snap/pycharm-community/256', 'USER': 'spartak',
            'SNAP_REAL_HOME': '/home/spartak', 'XDG_MENU_PREFIX': 'gnome-', 'GIO_LAUNCHED_DESKTOP_FILE_PID': '122719',
            'QT_ACCESSIBILITY': '1', 'PYTHONDONTWRITEBYTECODE': '1', 'LC_NUMERIC': 'ru_RU.UTF-8',
            'GJS_DEBUG_OUTPUT': 'stderr', 'SSH_AUTH_SOCK': '/run/user/1000/keyring/ssh', 'PYTHONUNBUFFERED': '1',
            'GNOME_SHELL_SESSION_MODE': 'ubuntu',
            'SNAP_CONTEXT': 'AoM6cqDJGx0xxWBUHLXWyVdhoNwTuHJsXSu2foumZWGYLCOaeHoL', 'XDG_RUNTIME_DIR': '/run/user/1000',
            'SNAP_COOKIE': 'AoM6cqDJGx0xxWBUHLXWyVdhoNwTuHJsXSu2foumZWGYLCOaeHoL', 'HOME': '/home/spartak',
            'QT_QPA_PLATFORM_PLUGIN_PATH': '/home/spartak/PycharmProjects/python_base/lesson_016/env/lib/python3.9/site-packages/cv2/qt/plugins',
            'QT_QPA_FONTDIR': '/home/spartak/PycharmProjects/python_base/lesson_016/env/lib/python3.9/site-packages/cv2/qt/fonts',
            'LD_LIBRARY_PATH': '/home/spartak/PycharmProjects/python_base/lesson_016/env/lib/python3.9/site-packages/cv2/../../lib64:'})
xiozqbni

xiozqbni1#

我从wayland和它的工作恢复到xorg,没有更多的警告
步骤如下:
1.通过取消注解/etc/gdm3/custom.conf中的WaylandEnable=false禁用Wayland
1.在/etc/environment中添加QT_QPA_PLATFORM=xcb
1.检查您是否使用Wayland或Xorg:

echo $XDG_SESSION_TYPE
9rnv2umw

9rnv2umw2#

在Wayland上绘制带有Pandas和matplotlib的图时,会出现相同的Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway。如果您不想停用Wayland并返回X11,您可以选择将图保存为pdf文件。
创建一些数据和图

import pandas
df = pandas.DataFrame({'x':range(0,30), 'y':range(10,40)})
df.set_index('x', inplace=True)
plot = df.plot(title='A nice line')

# Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

将图保存为pdf文件,如this answer中所述:

plot.get_figure().savefig('/tmp/output.pdf', format='pdf')

或者使用jupyter lab在浏览器中显示图。

相关问题