OpenCV not working properly with python on Linux with anaconda. Getting error that cv2.imshow() is not implemented

95,065

Solution 1

1.The easiest way:

conda remove opencv
conda update conda
conda install --channel menpo opencv

or (for OpenCV 3.1) :

conda install -c menpo opencv3

2.And if u don't want to do this, you can try to use matplotlib .

import cv2
import matplotlib.pyplot as plt

img = cv2.imread('img.jpg',0)

plt.imshow(img, cmap='gray')
plt.show()

3.Or try to build library by your own with option WITH_GTK=ON , or smth like that.

Update - 18th Jun 2019

I got this error on my Ubuntu(18.04.1 LTS) system for openCV 3.4.2, as the method call to cv2.imshow was failing. I am using anaconda. Just the below 2 steps helped me resolve:

conda remove opencv
conda install -c conda-forge opencv=4.1.0

If you are using pip, you can try

pip install opencv-contrib-python

Solution 2

I have had to deal with this issue a couple of times, this is what has worked consistently thus far:

conda remove opencv
conda install -c menpo opencv
pip install --upgrade pip
pip install opencv-contrib-python

Solution 3

🚀 Working method (👨‍🔬 tested on April 19, 2019)

  • 🐞 These error happen because of conda.
  • 🏹 Open Anaconda Prompt and remove conda opencv if installed
  • 👨‍💻 conda remove opencv

📢 If you have conda env, firstly activate it conda activate <your_env_name>

  • ⏬ After install opencv via pip (click here to offical info)
  • 👨‍💻 pip install opencv-contrib-python

📢 if pip haven't installed, use conda install pip command.

Solution 4

If you installed OpenCV using the opencv-python pip package at any point in time, be aware of the following note, taken from https://pypi.python.org/pypi/opencv-python

IMPORTANT NOTE MacOS and Linux wheels have currently some limitations:

  • video related functionality is not supported (not compiled with FFmpeg)
  • for example cv2.imshow() will not work (not compiled with GTK+ 2.x or Carbon support)

Also note that to install from another source, first you must remove the opencv-python package

Solution 5

For me (Arch Linux, Anaconda with Python 3.6), installing from the suggested channels menpo or loopbio did not change anything. My solution (see related question) was to

  1. install pkg-config (sudo pacman -Syu pkg-config),
  2. remove opencv from the environment (conda remove opencv) and
  3. re-install opencv from the conda-forge channel (conda install -c conda-forge opencv)

conda list now returns opencv 3.3.0 py36_blas_openblas_203 [blas_openblas] conda-forgeand all windows launched using cv2 are working fine.

Share:
95,065
Job Martinez
Author by

Job Martinez

Computer Science graduate looking for new challenges and opportunities. Gamer as well on the side.

Updated on July 08, 2022

Comments

  • Job Martinez
    Job Martinez almost 2 years

    This is the exact error that I am getting. My OS is Ubuntu 16.10.

    OpenCV Error: 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 cvShowImage, file /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp, line 545 Traceback (most recent call last): File "untitled.py", line 7, in cv2.imshow('image',img) cv2.error: /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp:545: error: (-2) 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

    my code is:

    import numpy as np
    import cv2
    
    # Load an color image in grayscale
    img = cv2.imread('0002.png',0)
    
    cv2.imshow('image',img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    0002.png is an image in the same directory as the program. I first installed anaconda with python 3.5, then I installed opencv by using the command

    conda install -c conda-forge opencv
    

    I installed libgtk2.0-dev just as the error said to but I still get the same error. Any help would be much appreciated. I've been trying to solve this for several hours.

  • nekketsuuu
    nekketsuuu almost 7 years
    Or you can use conda install --channel loopbio --channel conda-forge --channel pkgw-forge gtk2 ffmpeg ffmpeg-feature gtk2-feature opencv. (Details here.)
  • shaman.sir
    shaman.sir almost 7 years
    For conda (actually, Miniconda) it is better to use environments. Also, seems opencv installation temporaty fails for conda and Python 3.6, so for now it should be conda create --name py3 python=3.5, then activate py3, then conda install -c menpo opencv3.
  • Khanh Le
    Khanh Le over 6 years
    Can you explain what is the "your opencv directory"?
  • Khanh Le
    Khanh Le over 6 years
    UPDATE : opencv-python 3.4.0.12 has supported video related functions, so we can use pip install opencv-python as normal.
  • Dang Manh Truong
    Dang Manh Truong about 6 years
    @LittleZero: I still get this error: /io/opencv/modules/highgui/src/window.cpp:331: error: (-215) size.width>0 && size.height>0 in function imshow
  • Mona Jalal
    Mona Jalal about 6 years
    after putting more than 1 hour to solving this issue, finally this answer worked for me! Thanks a lot!!!
  • Mona Jalal
    Mona Jalal almost 6 years
    $ conda install gtk2 pkg-config Solving environment: failed PackagesNotFoundError: The following packages are not available from current channels: - gtk2
  • VelikiiNehochuha
    VelikiiNehochuha over 5 years
    It is unzip folder of archive from wget github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip
  • Peter
    Peter over 5 years
    Yep, this worked for me when Alex Glinsky's answer didn't.
  • Amir Hossein F
    Amir Hossein F over 5 years
    for future readers: only this worked for me: conda install -c menpo opencv3. the first one does not fix the problem (conda install --channel menpo opencv)
  • Himal Acharya
    Himal Acharya about 5 years
    This also worked me. I spend number of hours to solve this this.. finally it worked
  • aspiring1
    aspiring1 about 5 years
    One solution is to use virtualenv and create a virtualenv and use pip install numpy, pip install matplotlib and pip install opencv-contrib-python , etc to install after activating the environment, instead of using conda, for me the above solutions didn't work, but using a virtual environment is a great solution.
  • HelloGoodbye
    HelloGoodbye almost 5 years
    Why do you specify --channel menpo when installing opencv? I can install it without using that channel. (Surely, I'm not getting another package by using the default channel, am I?)
  • catox
    catox almost 5 years
    Worked for me with Miniconda on MX Linux.
  • Ambareesh
    Ambareesh over 4 years
    @LittleZero 's comment is Gold! Been looking for hours for something that worked!
  • Milan
    Milan over 4 years
    Take me 2 day to finally make it work...thank you very much
  • horaceT
    horaceT over 4 years
    Today is Jan 24, 2020. This does NOT work. However, the solution suggested by @Yedhrab below does work.
  • Sameer Pusegaonkar
    Sameer Pusegaonkar about 4 years
    Where can I find the opencv directory on anaconda?
  • Nic Szerman
    Nic Szerman about 4 years
    I like all the emojis!
  • Bersan
    Bersan almost 4 years
    I got Found conflicts! Looking for incompatible packages. after removing opencv, but let's see if it can fix itself. (to be precise, it showed the message when trying to install again opencv, after uninstalling it) edit: Ok, it worked, thanks !
  • marionmaiden
    marionmaiden over 3 years
    saved my night!
  • Druss2k
    Druss2k over 3 years
    01.01.2021!I am running ubuntu 18.04 on AWS. In my conda-env only numpy and opencv (installed as suggested are installed). It worked (more or less) as I get an different error (at least some progress): This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: xcb.
  • Volkov Maxim
    Volkov Maxim about 3 years
    Worked for Ubuntu 20.04. Thank you!
  • tjiagoM
    tjiagoM about 3 years
    12.04.2021 and this was the only solution for my conda environment with python 3.7. Seems like all the conda channels were not installing opencv correctly, and only pip did that well.