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.
-
where did you see that "suggestion" to use apt to install an OpenCV package? link please.Christoph Rackwitz– Christoph Rackwitz2024年11月23日 09:16:10 +00:00Commented Nov 23, 2024 at 9:16
-
1sorry it was the opencv website: docs.opencv.org/4.x/d2/de6/tutorial_py_setup_in_ubuntu.htmlStephen– Stephen2024年11月23日 14:24:37 +00:00Commented Nov 23, 2024 at 14:24
-
Thanks for getting back to me. The docs are outdated in plenty of locations. I was afraid that was the case here. If you're interested in making a contribution, that should be an easy task. Just open an issue about it, then throw them a PR referencing the issue. The file containing that tutorial's source is github.com/opencv/opencv/blob/master/doc/py_tutorials/py_setup/…Christoph Rackwitz– Christoph Rackwitz2024年11月23日 18:24:09 +00:00Commented Nov 23, 2024 at 18:24
2 Answers 2
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 OpenCV. 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 from apt is usually stale. Feel free to remove that old OpenCV 4.5 that you got from apt. It'll be something like sudo 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.
2 Comments
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.