Score:0

How to use opencv-python on WSL2 Ubuntu20.04

in flag

I have just installed a Ubuntu-20.04 on WSL2. And I installed a miniconda env with python 3.7, and then I installed opencv-python by "conda install opencv". But when I try the simplest cv2.imshow, it complains below:

cv2.error: OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474/work/modules/highgui/src/window.cpp:632: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

By the way, I can show plotting window by matplotlib.pyplot after I installed a VcXsrv and export DISPLAY=host_ip_in_wsl2:1.1. And I also make my GPU works after installed Windows 10 November 2021 update, CUDA driver for WSL2, and CUDA toolkit 11.0. I can get Tensorflow 2.4.1 working well with GPU. I can compile darknet with GPU and use it for YOLO v1.

I googled some. They say uninstall opencv and reinstall from channel menpo can do it. But this post is 5 years ago and not for WSL.

I also saw some posts demonstrate a tedious procedure to compile opencv-python from source.

So, how to use opencv-python on Ubuntu-20.04 of WSL2? Easy approaches like "conda install ..." or "pip install ..." is preferred. Compiling from source is also acceptable.

Nmath avatar
ng flag
If errors are asking for GTK, you might not be able to use this software on WSL since WSL currently does not officially support a desktop environment. GTK is associated with desktop environment functionality. If you want a fully fledged Ubuntu experience on Windows, you can install Ubuntu in a VM like VirtualBox.
cmpltrtok avatar
in flag
@Nmath, but the WSL2 approach is the only way I know to use GPU other than the unacceptable dual-boot when Windows and GPU be both musts. Any hopes?
Nmath avatar
ng flag
Dual boot configuration is probably your only option.
Score:0
in flag

I solved this problem by install opencv-python by pip.

$ pip install opencv-python

But I don't understand why pip works when conda install opencv does not. If anybody knows the detail, could you give me some clue?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.