Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

python - Problem using OpenCV in WSL, when opening windows

I am using WSL, and when running some Python code with OpenCV that needs to open a different window, it throws an error. This is the code:

import cv2 as cv

image = cv.imread("images/pic.jpg")
cv.imshow(0)
cv.waitKey(0)

And this is the error I get

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)
question from:https://stackoverflow.com/questions/65939167/problem-using-opencv-in-wsl-when-opening-windows

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to enable your environment for GUI application on WSL.

Using the GUI for enabling Windows features

  1. Open the Start Menu and search Turn Windows features on or off
  2. Select Windows Subsystem for Linux
  3. Click OK
  4. Restart your computer when prompted

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...