Python 打开窗口时,在WSL中使用OpenCV时出现问题

Python 打开窗口时,在WSL中使用OpenCV时出现问题,python,linux,opencv,computer-vision,windows-subsystem-for-linux,Python,Linux,Opencv,Computer Vision,Windows Subsystem For Linux,我使用的是WSL,当使用OpenCV运行一些需要打开不同窗口的Python代码时,它会抛出一个错误。 代码如下: import cv2 as cv image = cv.imread("images/pic.jpg") cv.imshow(0) cv.waitKey(0) 这就是我得到的错误 qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plu

我使用的是WSL,当使用OpenCV运行一些需要打开不同窗口的Python代码时,它会抛出一个错误。 代码如下:

import cv2 as cv

image = cv.imread("images/pic.jpg")
cv.imshow(0)
cv.waitKey(0)
这就是我得到的错误

qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/user/.local/lib/python3.8/site-packages/cv2/qt/plugins" 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: xcb.

Aborted (core dumped)

您需要为WSL上的GUI应用程序启用您的环境

  • 打开“开始”菜单并搜索打开或关闭Windows功能
  • 选择Linux的Windows子系统
  • 单击“确定”
  • 出现提示时重新启动计算机

  • 使用pip使用以下命令升级OpenCV

    pip3 install --upgrade opencv-python==4.3.0.36
    

    对我来说还是一样,不工作你安装了qt版本吗?也许您可以尝试
    安装libqt5gui5