1

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.

wohlstad
36.6k18 gold badges79 silver badges113 bronze badges
asked Nov 23, 2024 at 1:45
3
  • where did you see that "suggestion" to use apt to install an OpenCV package? link please. Commented Nov 23, 2024 at 9:16
  • 1
    sorry it was the opencv website: docs.opencv.org/4.x/d2/de6/tutorial_py_setup_in_ubuntu.html Commented 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/… Commented Nov 23, 2024 at 18:24

2 Answers 2

3

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.

  1. Run pip3 list. Look for your headless OpenCV. That step is optional but you'll learn something.

  2. Remove the headless package with pip3 uninstall opencv-python-headless.

  3. 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.

answered Nov 23, 2024 at 9:12
Sign up to request clarification or add additional context in comments.

2 Comments

excellent answer, I learned.
by the way, the headless package could have come from some other (pip) package pulling it in as a dependency.
0

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.

answered Nov 23, 2024 at 6:31

2 Comments

that won't remove the version that wasn't installed by apt
that remove the version he installed with apt. Debian and derived distros advice against the use of non-Debian-packaged Python packages.But I agree with your answer, use virtual environments and pip3 to install the versions needed.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.