I'm trying to get OpenCV working with Python on my Ubuntu machine. I've downloaded and installed OpenCV, but when I attempt to run the following python code (which should capture images from a webcam and push them to the screen)
import cv
cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
capture = cv.CaptureFromCAM(0)
def repeat():
frame = cv.QueryFrame(capture)
cv.ShowImage("w1", frame)
time.sleep(10)
while True:
repeat()
I get the following 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
So I do what they ask: install the packages, move to the folder from whence I installed OpenCV, and run
sudo make uninstall
make
sudo make install
But when I try to run the python, it gives me the same error. Am I missing something?
If it's giving you errors with gtk, try qt.
sudo apt-get install libqt4-dev
cmake -D WITH_QT=ON ..
make
sudo make install
If this doesn't work, there's an easy way out.
sudo apt-get install libopencv-*
This will download all the required dependencies(although it seems that you have all the required libraries installed, but still you could try it once). This will probably install OpenCV 2.3.1 (Ubuntu 12.04). But since you have OpenCV 2.4.3 in /usr/local/lib include this path in /etc/ld.so.conf and do ldconfig. So now whenever you use OpenCV, you'd use the latest version. This is not the best way to do it but if you're still having problems with qt or gtk, try this once. This should work.
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 (e.g., at the line of cv2.namedWindow(name) with error: cv2.error: OpenCV(3.4.2). The function is not implemented.). 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
Don't waste your time trying to resolve this issue, this was made clear by the makers themselves. Instead of cv2.imshow() use this:
img = cv2.imread('path_to_image')
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
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
It's because of 'opencv-python-headless'. Uninstall it!
pip uninstall opencv-python-headless
I hope this answer is still useful, despite problem seems to be quite old.
If you have Anaconda installed, and your OpenCV does not support GTK+ (as in this case), you can simply type
conda install -c menpo opencv=2.4.11
It will install suitable OpenCV version that does not produce a mentioned error. Besides, it will reinstall previously installed OpenCV if there was one as a part of Anaconda.
Before installing libgtk2.0-dev and
pkg-config or libqt4-dev. Make sure that you have uninstalled opencv. You can confirm this by running import cv2 on your python shell. If it fails, then install the needed packages and re-run cmake .
This is due to some kind of overlap in opencv-python against opencv-contrib-python, opencv-python-headless packages. Simply uninstall both headless & contrib.
pip uninstall opencv-contrib-python
pip uninstall opencv-python-headless
Then uninstall opencv-python.
pip uninstall opencv-python
it's a clean slate here.
Then install only OpenCV-python which will clear you out of this issue.
pip install opencv-python
This strange problem started to happen to me as well, in one virtual environment out of several that I'm using. What solved it is to uninstall opencv and then reinstall it:
pip uninstall opencv-python
pip install opencv-python
Related
My environment:
Ubuntu 18.0.4 LTS (also tried on 19.04)
I use/need python3 (3.6.8 installed)
I need cv2, which is a model of opencv.
I tried several receipts I found on the Internet, but nothing worked.
I tried to install as pre-compiled (sudo apt-get install python-opencv) - No error, but when I try the test:
import cv2 as cv
print(cv.__version__)
I get error module not found.
The problem seems that I have installed also anaconda. The above test uses then anaconda, and cannot find the module.
Compiling from source installed for python2, but I do need python3. (The test also uses anaconda)
One of my receipts worked till the end, but with the line:
workon OpenCV-master-py3
It gaves me the error workon not found.
I tried then to install via Conda, but that wants to downgrade Conda.
Is there a way to run it without anaconda and find a replacement for
"workon OpenCV-master-py3"
For python3 you can simply do pip3 install opencv-python and it will work.
using workon
creating virtual environment
mkvirtualenv -p python3 opencv
Inside the virtual environment.
If you are only working with images
pip install opencv-python
opencv-python
If you need support for working videos
pip install opencv-contrib-python
opencv-contrib-python
If you need a non GUI opencv
pip install opencv-python-headless
opencv-python-headless
If you need to install specific version you can use == to check the available version first like
pip install opencv-python== ,then install the version you require
I need to install cv2 for a script that has been written for me. I tried pip install cv2 and pip install open_cv and got the same problem - a warning message from dist.py and complains about zlib being not found. No cv2 installed. I also tried pyopenvc and pip install opencv-python.
So, I went to the opencv site and downloaded the relevant exe. Ran it - generated a heap of subdirectories and a make file and stuff.
What do I do now?
Install opencv-python (which is an unofficial pre-built OpenCV package for Python) by issuing the following command:
pip install opencv-python
run the following command by creating a virtual enviroment using python 3 and run
pip3 install opencv-python
to check it has installed correctly run
python3 -c "import cv2"
In pip package management, there are 4 different OpenCV packages all using the same namespace, cv2. Although they are not officially supported by OpenCV.org, they are commonly used in developers' community. You could install any of them using the following command:
pip install PACKAGE_NAME
where PACKAGE_NAME can be
opencv-python (only contains main modules)
opencv-contrib-python (contains both main and contrib modules)
opencv-python-headless (same as opencv-python but without GUI functionality)
opencv-contrib-python-headless (same as opencv-contrib-python but without GUI functionality)
You should only install one of them depending on your needs. If you accidentally installed multiple of them in the same environment, you can remove them using pip uninstall before installing the correct one again.
For more details, you can refer to the project description of OpenCV on Wheels.
As of 2021, all of these 4 packages are official OpenCV projects. Source: OpenCV Website.
To Install the Current Latest version of OpenCV then use the below commands:
Use this Command:
pip install --upgrade opencv-python
If you're facing problem in above command then try this :
pip install --upgrade opencv-contrib-python
To check the version of installed OpenCV:
import cv2
print(cv2.__version__)
Simply use this for the so far latest version 4.1.0.
pip install opencv-contrib-python==4.1.0.25
For the default version use this:
pip install opencv-contrib-python
If you have a new Raspberry Pi and want to install OpenCV then this tutorial would be a good choice.
For Ubuntu/Linux users:
sudo apt install python3-opencv
As of 10/22/2019, I think the best answer is simply
conda install opencv
It appears opencv is now in the main Anaconda channel.
To see which packages (including opencv) are in the main Anaconda channel go to Anaconda Package Lists and follow the link corresponding to your python version and os version.
Everybody struggles initially while installing OpenCV. OpenCV requires a lot of dependencies in the backend. The best way to start with OpenCV is, install it in a virtual environment. I suggest that you use the Python Anaconda distribution and create a virtual environment using it. Then inside the virtual environment, you can install OpenCV using this command:
conda install -c conda-forge opencv
Please follow the command:
pip install opencv-python
then if you want to use:
import cv2
If it's not worked due to any update, please follow the documentation
Make a virtual enviroment using python3
virtualenv env_name --python="python3"
and run the following command
pip3 install opencv-python
to check it has installed correctly run
python3 -c "import cv2"
To install open_cv you can go to this website or do this,
pip install opencv-contrib-python --upgrade
pip install opencv-python
You can test it by:
C:\> python
>>> import cv2
>>> print(cv2.__version__)
'4.5.1' # your version may be a newer one
You can install opencv the normal way:
pip install opencv-python
If you are getting errors, you can do this:
pip install opencv-python-headless
Open anaconda command prompt and type in below command.
conda install -c conda-forge opencv
Once the 'Solving environment' is done. It will ask to download dependencies. Type 'y'.
It will install all the dependencies and then you are ready to code.
I recommend this for Python 3: Please install it this way with pip
pip3 install opencv-python
This will download and install the latest version of OpenCV.
You could try using below command-
pip install opencv-contrib-python
It will basically download the compatible version. If this command fails, you could upgrade you pip using below command-
python -m pip install –upgrade pip
If you need a pictorial guide, head over to Simple Steps to Install OpenCV in Windows
You can also try installing OpenCV from prebuilt binaries from the official OpenCV site.
->pip install opencv-python you can use this.
But if this code does not working then you can check python version on cmd and anaconda because they are different. So you type command in anaconda prompt and cmd, it will work. You can check this -> pip list
Open terminal
Run the following command
pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org opencv-python.
Hope it will work.
Installing cv2 or opencv-python using pip is sometimes a problem. I was having the same problem of installing cv2 with pip. The installation wasn't a problem the problem was to import cv2 after installation. I was getting an Import Error so to fix this i import main from pip to install opencv-python. Try to run the following code in your python file then opencv-python will be installed
from pip._internal import main as install
try:
import cv2
except ImportError as e:
install(["install", "opencv-python"])
finally:
pass
I hope this will help someone
As a reference it might help someone... On Debian system I hard to do the following:
apt-get install -y libsm6 libxext6 libxrender-dev
pip3 install opencv-python
python3 -c "import cv2"
On Ubuntu you can install it for the system Python with
sudo apt install python3-opencv
if you are using Pycharm navigate settings > Project:name > Project interpreter just search the module by name(in this case OpenCV-python) and install it. worked for me
In case you use aarch64 platform with ARM64 cpu - and/or docker
On a development board on ARM64, no python-opencv version were found at all
version: NONE.
I've had to build from source. This allowed to include CUDA support.
In my case it was already available on the board but it wasn't found on the development environment.
If compiling from source is out of reach, there are Dockers
Of course compiling will take some time (few hours on ARM core), but it is worthy process to know as most open source tools can be built this way in case of issues.
I've had this problem in Google Colab, It only worked with this specific package version.
!pip install "opencv-python-headless<4.3"
There are two options-
pip install cv2
or
pip install opencv-python
Hope it helps.
I am using opencv2 in python with the code
import cv2
cv2.namedWindow("output", cv2.WINDOW_NORMAL)
cv2.imshow("output",im)
cv2.resizeWindow('output', 400,400)
cv2.waitKey(0)
cv2.destroyAllWindows()
I have the error as
QObject::moveToThread: Current thread (0x1d2c9cf0) is not the object's thread (0x1d347b20).
Cannot move to target thread (0x1d2c9cf0)
I debug and found that it happened when I use cv2.waitKey(0). How should I fix it? Thanks
Update: I am using 3.3.0.0. If I use older version, I have error
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 cvDestroyAllWindows, file /io/opencv/modules/highgui/src/window.cpp, line 577
Traceback (most recent call last):
File "tools/demo_handbone.py", line 220, in <module>
demo(net, im_name)
File "tools/demo_handbone.py", line 159, in demo
cv2.destroyAllWindows()
cv2.error: /io/opencv/modules/highgui/src/window.cpp:577: 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 cvDestroyAllWindows
I got same problem, it was from opencv-python version problem for me.
My Linux machine's environment is as following:
$ cat /etc/lsb-release
...
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
$ date
Tue Aug 11 11:43:16 KST 2020
$ python --version
Python 3.7.8
$ pip list|grep Qt
PyQt5 5.15.0
PyQt5-sip 12.8.0
$ pip list|grep opencv-python
opencv-python 4.3.0.38
I downgraded opencv-python 4.3.0.38 to 4.3.0.36.
$ pip uninstall opencv-python
$ pip install opencv-python==4.3.0.36
$ pip list|grep opencv-python
opencv-python 4.3.0.36
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 can happen if you are using an Anaconda virtual environment and did both conda install pyqt(1) and pip install opencv-python. This creates a conflict between the two PyQt versions (opencv-python ships with its own) and causes the errors.
The solution is to install PyQt via pip, i.e. pip install PyQt5.
(1) Or anything that depends on pyqt, e.g. conda install matplotlib.
I was able to fix this problem by installing new pyqt.
if you are using anaconda, just write down below:
$ conda install pyqt
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:
installing using pip3 install opencv-python
installing using apt install python-opencv
I followed #areche solution, I end up with 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 environments
pip3 uninstall opencv-python on all instances of my python and virtual environments
sudo 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.
Just reinstall opencv-python lib, it's OK.
pip uninstall opencv-python
pip install opencv-python=4.2.0.34
The version 4.2 is the latest opencv python that don't throw this error. I tried 4.3 or 4.4 +, it's don't work.
The main reason of this question may be the confliction between PyQt5 and Opencv.
refer to: https://blog.csdn.net/flyfor2013/article/details/110132458
pip3 uninstall opencv-python
pip3 install opencv-python==4.1.1.26
when I downgrade opencv-python 4.5 -> 4.1.1.26 then Ok
pip3 >= 20.3 use: pip3 install --use-deprecated=legacy-resolver opencv-python==
pip3 >= 9.0 use: pip3 install opencv-python==
and I try
pip3 uninstall opencv-python
pip3 install opencv-python==4.3.0.36
Ok, too
The openCv author says that this problem comes from different Qt versions in openCv and the linux distro. That is: openCv comes with Qt4, but Qt5 is already installed.
This problem is due to the conflict between opencv-python's own Qt5 and the one used by other packages. In my case, matplotlib is installed via conda, then pyqt is also installed as a matplotlib's dependency. My solution is as follows:
Uninstall matplotlib: conda remove matplotlib
Install opencv-python and matplotlib: pip install matplotlib opencv-python
Now, matplotlib installed via pip doesn't require pyqt and the conflict is solved.
Note: The latest version 4.5.4.x gets error with python 3.9, consider using lower version such as 4.5.1.x in this case.
The issue is with OpenCV version, The following version solved all issues for me.
pip uninstall opencv-python
pip install opencv-python==4.1.2.30
I am using - Python 3.8.5 with conda
I tried with upgrading pyqt too but it didn't work
I tried the above mentioned method and could get opencv module working for my project which uses python3.x interpreter.
After performing few experiments, i got it working by doing the below steps:
1) Install opencv-python in your machine using:
sudo pip3 install opencv-python
2) On the python3.x terminal find the version:
>>> import cv2
>>> cv2.__version__
'3.4.1'
3) Get the same version of OpenCV from their official page.
4) Perform the CMake settings as mentioned in opencv tutorial.
Note the location specified in PYTHON3_PACKAGES_PATH
5) Once build has been performed, got to the install location specified in PYTHON3_PACKAGES_PATH. Move the library named cv2.cpython-*-gnu.so to the current python3.x dist-packages path:
usr/local/lib/python3.5/dist-packages/cv2
6) Reload your python3 project and try again!
This problem not present if runing opencv without virtualenviroment.
My system:
Kbuntu 18.04 LTS
GTX 1050
CUDA 9.2
Tensorflow 1.9
I had the same problem when i tried to run a detectron2 demo. My OS is Centos7 and i
uninstall some applications about qt.
find applications about qt.
yum list installed |grep qt
remove applications
yum -y remove xxx...
This error occurs in higher versions of openCv like 4.3.0.38 or higher, i tried 4.3.0.36 version with pip and this problem solved for me, but in lower version i were facing lots of problems, like window not loading correctly,If are using Ubuntu i would recommend you to uninstall opencv from your system completely and try to reinstall with command given below,
pip install opencv-contrib-python3
It is the compatibility issue. Even the way of "conda install install pyqt" does work. Please make sure that you can install the opencv libraries with the specific versions. Higher versions may incur the same issues.
pip install opencv-python==4.1.1.26
pip install opencv-contrib-python==4.1.1.26
Cheers,
I had the same problem and I did not find any solution. By trial and error, I found that my OpenCV version is corrupted. As a result, I deleted it and install a new fresh one. You can use one of these two options:
1. Terminal
run brew uninstall opencv3 to uninstall opencv
then install it using sudo apt-get install libopencv-dev python-opencv command.
2. Anaconda
Actually, I used this method for my own problem.
open anaconda
go to the environment section and select your environment as follow:
then click on installed and search for opencv:
select opencv package and uninstall it. then try to re-install opencv by selecting not installed and searching for opencv. be careful to install the correct version.
In my application I wanted to use PyQt without any of opencv's GUI functionality, so the solution was to remove my current vertion of opencv-python, then instead pip install opencv-python-headless (or opencv-contrib-python-headless if you prefer). That way, opencv would be installed without its conflicting Qt library.
See: https://github.com/opencv/opencv-python#installation-and-usage
Downgrade the python version from 3.9.13 to 3.8.10
conda install python=3.8.10
pip install opencv-python==4.5.2.54
worked for me.
My system environment: Ubuntu 20.04 Anaconda 3.8
I was used matplotlib to display images and face this problem.
pip install opencv-python-headless not work for me.
pip uninstall pyqt5 then pip install pyqt5==5.12 and it works well.
The answer of #Mateen works great if you have Ubuntu version 17 and above. For Ubuntu 16, it's better to compile from sources your opencv python. As #Varun mentioned, follow the opencv tutorial. However, to successfully compile opencv with python 3 I have to add some flags in cmake command:
cmake -DCMAKE_BUILD_TYPE=RELEASE -DPYTHON_DEFAULT_EXECUTABLE=$(which python3) -DPYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python3.5m/ -DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.5/dist-packages/numpy/core/include/ ..
Hope that will be helpful.
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 don't know why, but installation of matplotlib solved for me the problem with the error
QObject::moveToThread: Current thread (0x1d2c9cf0) is not the object's thread (0x1d347b20).
Cannot move to target thread (0x1d2c9cf0)
I emphasize that I prepared fresh conda environment where matplotlib was installed. Opencv was installed by pip in conda env as follow pip install opencv-python opencv-contrib-python.
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 had the same problem. Using opencv imshow function raised the moving thread error. Eventually, I found that Ubuntu 16.04 has a preinstalled pyqt5 while OpenCV needs pqty4.
Therefore, this may be caused by conflicting installations of Qt libraries. The following command fixed it for me:
sudo apt-get remove libqt5x11extras5 libqt5x11extras5-dev
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.
In case you are using matplotlib, see this answer: https://stackoverflow.com/a/49887744/13268880
TL;DR: matplotlib.use('Agg')
This may be caused by conflicting installations of Qt libraries. The following command fixed it for me:
sudo apt-get remove libqt5x11extras5 libqt5x11extras5-dev
I want to use opencv under python 3 in Ubunto 14.04. I plan to use the PyCharm IDE to develop my program.
Inside PyCharm I choose, I set:
File/Settings/Project:HelloWorld/Project Interpreter/3.4.3(/usr/bin/python3.4)
Python 3.4.3 is the default version of python in Ubunto 14.04.
Then I try to add opencv-python package:
File/Settings/Project:HelloWorld/Project Interpreter/+ (where you add the package)
and the system gives me this error:
Executed command:
pip install opencv-python
Try to run this command from the system terminal. Make sure that you
use the correct version of 'pip' installed for your Python interpreter located at '/usr/bin/python3.4'.
DEPRECATION: --no-install, --no-download, --build, and --no-clean are deprecated. See https://github.com/pypa/pip/issues/906.
Downloading/unpacking opencv-python
Could not find any downloads that satisfy the requirement opencv-python
Cleaning up...
No distributions at all found for opencv-python
Storing debug log for failure in /root/.pip/pip.log
the error is the same when I run the command from terminal. I believe the problem is related to installing opencv under python3 but I am not sure I know if I can fix it. Please let me know your opinion.
Thanks
The fix is to update your pip and try again. This worked for me.
So, first:
pip install --upgrade pip
after that:
pip install opencv-python
First, you should not use install opencv-python, this is not the official opencv package.
Please, see:
**SOLVED** How to include libgtk2.0-dev and pkg-config in cmake when installing openCV on Ubuntu 16
If you want to install opencv, you can follow this website, that worked for me. You might need to apapt some parts (mainly version numbers, and paths during the cmake process).
I also faced similar issue in the windows and pip upgrade worked for me,
pip install --upgrade pip
and install using below command,
pip install opencv-python
As far as I can see from querying pip (using pip search opencv) there is no package called opencv-python I think the one you're looking for is pyopencv.
this issue appears to be almost identical
I've been trying to install both OpenCV and cv2 from both Pycharm and from the terminal as suggested using:
pip install --user opencv
pip install --user cv2
but I'm getting the following error for them:
Collecting opencv
Could not find a version that satisfies the requirement opencv (from versions: )
No matching distribution found for opencv
and
Collecting cv2
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
How can I fix these and install the packages properly? I'm using python 3.4.
You are getting those errors because opencv and cv2 are not the python package names.
These are both included as part of the opencv-python package available to install from pip.
If you are using python 2 you can install with pip:
pip install opencv-python
Or use the equivilent for python 3:
pip3 install opencv-python
After running the appropriate pip command your package should be available to use from python.
This the correct command that you need to install opencv
pip install opencv-python
if you get any error when you are trying to install the "opencv-python" package in pycharm, make sure that you have added your python path to 'System Variables' section of Environment variables in Windows.
And also check whether you have configured a valid interpreter for your project
I ran into the same problem. One issue might be OpenCV is created for Python 2.7, not 3 (not all python 2.7 libraries will work in python 3 or greater). I also don't believe you can download OpenCV directly through PyCharm's package installer. I have found luck following the instructions: OpenCV Python. Specifically:
Downloading and installing OpenCV from SourceForge
Copying the cv2.pyd file from the download (opencv\build\python\2.7\x64) into Python's site-packages folder (something like: C:\Python27\Lib\site-packages)
In PyCharm, open the python Console (Tools>Python Console) and type:import cv2, and assuming no errors print cv2.__version__
Alternatively, I have had luck using this package opencv-python, which you can straightforwardly install using pip with pip install opencv-python
Good luck!
python3.6 -m pip install opencv-python
will install cv2 in python3.6 branch
On Windows:
!pip install opencv-python
Try this. I am using Jupyter notebook (OS: Ubuntu 16.04 LTS on Google Cloud Platform + on Windows). Executed following command in the Jupyter notebook to install opencv:
!pip install opencv-contrib-python #working on both Windows and Ubuntu
After successful installation you will get following message:
Successfully installed opencv-contrib-python-4.1.0.25
Now restart the kernel and try to import opencv as:
import cv2
The same command can be used to installed opencv on Windows as well.
SOLUTION 2: try following commands to install opencv:
For Ubuntu:
Run following command from terminal:
sudo apt-get install libsm6 libxrender1 libfontconfig1
Restart Jupyter notebook kernel and execute following command:
!pip install opencv-contrib-python
NOTE: You can run all the above commands from the terminal as well without using '!'.
Keep it simple and just run.
pip install opencv-python
This is the simplest way of installing opencv.
If you still face issue, create a virtual environment and try installing opencv.
I rather use Virtualenv to install such packages rather than the entire system, saves time and effort rather than building from source.
I use virtualenvwrapper
Windows user can download
pip install virtualenvwrapper-win
https://pypi.org/project/virtualenvwrapper-win/
Linux follow
pip install opencv-python
opencv-python
If processing a video is required
pip install opencv-contrib-python
opencv-contrib-python
If you do not need GUI in Opencv
pip install opencv-contrib-python-headless
opencv-contrib-python-headless
here is a tutorial that worked for me without any problem.
Copied from the site above the important part:
Download the OpenCV version corresponding to your Python installation
from here. In my case, I’ve used
opencv_python-3.1.0-cp35-cp35m-win32.whl.
Now, open a cmd window like before. You can open this directly in your
Downloads folder if you SHIFT and right click inside it. The idea is
to open a cmd window where you’ve downloaded the above [...] file. Use
the [...] command to install [...] OpenCV:
1 pip install "opencv_python-3.1.0-cp35-cp35m-win32.whl"
Additional note: don't forget to change the name of the downloaded file in the command you use.
Apparently by installing opencv, you'll have access to cv2 too.
Installing opencv is not that direct.
You need to pre-install some packages first.
I would not recommend the unofficial package opencv-python. Does not work properly in macos and ubuntu (see this post). No idea about windows.
There are many webs explaining how to install opencv and all required packages.
For example this one.
The problem of trying to install opencv several times is that you need to uninstall completely before attempting again, or you might end having many errors.
you must install opencv-python
pip/pip3 install opencv-python
if you try import opencv-python, receive error.
Fix this error, use the import cv2
How about try some different mirrors?
If you are in China, I highly recommend you try:
sudo pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ opencv-contrib-python
If not, just replace the url address to some other mirrors you like!
Good luck.
this will help you
pip3 install opencv-python
this is the snippet of successful installation
First step:
pip uninstall numpy
pip uninstall opencv-python
Second step:
pip install numpy
pip install opencv-python
I had the same problem. Here are the steps for Windows 10 users.
Open CMD: win+r then type cmd. Now,
Type pip install virtualenv
Create a Virtual Environment, Type virtualenv testopencv
Get Inside testopencv, Type cd testopencv
Activate the Virtual Environment, Type .\Scripts\activate
Now Install Opencv, Type pip install opencv-contrib-python --upgrade
Let's test Opencv, Type Python then import cv2 hit enter then type print(cv2.__version__) to check if its installed
Now, open a new cmd, win + r then type cmd, repeat step 6. If it gives you an error.
Go inside the testopencv folder, inside lib. Copy everything, go to your python directory, inside lib folder paste it and skip that are already present.
Again open a new cmd, repeat Step 6.
Hope it helps.
In win, download the py based latest numpy and Opencv from Unofficial Windows Binaries for Python Extension Packages and pip install its source in cmd. Later copy site-package folder from main py lib to venv lib.
In jetso nano this work for me.
$ git clone https://github.com/JetsonHacksNano/buildOpenCV
$ cd buildOpenCV
When I was facing this issue I used to install OpenCV in pycharm installed package panel where we can find under the settings tab. Search "OpenCV-python" and install it in the installed package panel of right interpreter.
First run from cmd
pip --version
to make sure that you have the updated version installed.
Then run
pip install opencv-python
Go through with this link: https://learnopencv.com/install-opencv-4-on-raspberry-pi/
you can install OpenCV perfectly with out any error. but the problem was it will take lot of time to install.
I had used pi3 model B+ with 32GB class10 SD card for me it took more than 12 hours for complete installation.
If you still find any error to install open-cv in your mac, try this:
opencv-python==4.2.0.34
This worked for me.