I am getting an error on running cv2.imshow()
cv2.imshow("Image", image)
cv2.error: OpenCV(4.9.0) /io/opencv/modules/highgui/src/window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa 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'
and following suggestions in this forum I did
sudo apt install python3-opencv
which installed opencv4.5d. the same code still threw an error and this time I saw the error was coming from opencv4.9. I do not remember installing it, but I found this
usr/local/lib/python3.10/dist-packages/opencv_python_headless-4.9.0.80.dist-info
/usr/local/lib/python3.10/dist-packages/opencv_python_headless.libs
How do I remove 4.9 or make python import 4.5 and not 4.9??
thanks everybody.
2
Answers
You have to remove opencv and its dependencies:
sudo apt remove python3-opencv and
sudo apt autoremove.
Then install again with the version you want:
sudo apt install python3-opencv=4.5.5
Hope it works.
Your problem isn’t the way the package was installed. Your problem is that you installed a headless package when you didn’t want that.
Run
pip3 list
. Look for your headless python. That step is optional but you’ll learn something.Remove the headless package with
pip3 uninstall opencv-python-headless
.Install a regular package with
pip3 install opencv-python
.Stick with installing OpenCV using pip. Don’t use
apt
to get OpenCV. The package coming fromapt
is usually stale. Feel free to remove that old OpenCV 4.5 that you got fromapt
. It’ll be something likesudo apt remove python3-opencv
.In case you need an older version of OpenCV, you can get that from pip too. Browse the release history of the package, click on the version you need. Up top there’s an install command you can copy. Then you can
pip3 install opencv-python==4.5.5.64
If you want multiple versions of a pip package side by side, you’ll have to start learning about virtual environments.