skip to Main Content

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


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

    Login or Signup to reply.
  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.

    1. Run pip3 list. Look for your headless python. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search