I installed opencv-python on ubuntu wsl, after setting up a venv using virtualenvwrapper (I use wsl in visual studio code). When running this code (which appears in one of the articles of this OCR guide:
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True)
args = vars(ap.parse_args())
image = cv2.imread(args["image"])
cv2.imshow("I", image)
with this command on teminal:
python script.py --image temp.png
I get:
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ben123/.local/bin/.virtualenvs/ocr_venv/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.
The interpreter in vscode is the correct one (the one of the venv), and when I type pip list
I get
Package Version
------------- --------
numpy 1.22.2
opencv-python 4.5.5.62
pip 22.0.3
setuptools 60.6.0
wheel 0.37.1
Would appreciate any help at this point, since I spent so much time and didn't get nowhere.
Things I tried:
- following this guide to install it. Gave the same error.
- following an older guide from this site, was much more complicated and didn't work as well.
- uninstalling opencv-python and installing opencv-python again/ opencv-python-contrib/ opencv-python-headless/ opencv-python-contrib-headless (only one of them at a time)
- following this thread because it has similar problem
- literally reset my wsl several times just to make sure I don't have multiple pythons/ opencv versions that mess this up.
- tried installing (to a wsl venv) opencv directly with the official documentation
- Tried to give up on wsl completely and install opencv using anaconda but even that didn't work.