I am using opencv2 in python with the code
import cv2
cv2.namedWindow(\"output\", cv2.WINDOW_NORMAL)
cv2.imshow(\"output\",im)
cv2.resizeWindow(\'outp
First, uninstall any versions of OpenCV you may have installed. If you installed using pip
:
sudo pip uninstall opencv-python
Next, try installing OpenCV using your Linux distro's package manager. For Ubuntu/Debian, this is:
sudo apt-get install libopencv-dev python-opencv
This problem not present if runing opencv without virtualenviroment. My system: Kbuntu 18.04 LTS GTX 1050 CUDA 9.2 Tensorflow 1.9
I solved this issue and I posted my solution in related issue on OpenCV github page. But for your convenience, I will post it here also.
In my case, I did almost all the solutions:
kdelibs5-plugins
which was an important module for most of my desktop environments, so I give up on uninstalling it.Finally, I found a solution for my case
pip uninstall opencv-python
on all instances of my python and virtual environmentspip3 uninstall opencv-python
on all instances of my python and virtual environmentssudo apt remove python-opencv
then I downloaded the most recent opencv, in my case opencv-4.1.1
, I build it.
for building :
mkdir build; cd build; ccmake ..
then I pressed pressed c
, again pressed c
, then pressed g
to generate make files, then
sudo make -j8
after successful building, I copied build\lib\python3\cv2.cpython.xxxxxx.so
to usr/local/lib/python3.5/dist-packages/
and renamed it to cv2.so
Do the same for each virtualenv that you have. ( I'm not sure if it is logical, but it worked for me).
then everything worked fine without any error.
I fixed this under Ubuntu 18.04 LTS by uninstalling any OpenCV packages from pip
and apt
and installing OpenCV directly from source. Maybe this tutorial will help:
https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/
I followed the solution suggested by @Varun and it worked for me (using Python 3).
However, I didn't install the built files, as I do not have the admin rights on the system where I need the cv package. A cmake
, followed by make
was enough, I then took the cv2.*.gnu
file from ../build/lib/python3
folder and replaced the one in the site-packages/cv2
folder of my virtual environment
I know the thread is a bit old but posting for anyone else out there, I faced the same problem and it was because even after running
pip3 uninstall opencv-python
there was another version of open-cv in my system which I checked by
pip list
(I'm guessing that pip only removes the first version it finds) So I ran this command again
pip3 uninstall opencv-python
And now simply installing opencv by
pip install opencv-python
worked for me.