[python] Pycharm/Python OpenCV and CV2 install error

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.

This question is related to python opencv pycharm

The answer is


this will help you

pip3 install opencv-python

this is the snippet of successful installation


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


I had the same problem. Here are the steps for Windows 10 users.

Open CMD: win+r then type cmd. Now,

  1. Type pip install virtualenv
  2. Create a Virtual Environment, Type virtualenv testopencv
  3. Get Inside testopencv, Type cd testopencv
  4. Activate the Virtual Environment, Type .\Scripts\activate
  5. Now Install Opencv, Type pip install opencv-contrib-python --upgrade
  6. 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.


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.


First step:

pip uninstall numpy
pip uninstall opencv-python

Second step:

pip install numpy
pip install opencv-python

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.


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


In jetso nano this work for me.

$ git clone https://github.com/JetsonHacksNano/buildOpenCV
$ cd buildOpenCV

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.


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.


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:

  1. Downloading and installing OpenCV from SourceForge
  2. 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)
  3. 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!


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 '!'.


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.


python3.6 -m pip install opencv-python

will install cv2 in python3.6 branch


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to opencv

Real time face detection OpenCV, Python OpenCV TypeError: Expected cv::UMat for argument 'src' - What is this? OpenCV !_src.empty() in function 'cvtColor' error ConvergenceWarning: Liblinear failed to converge, increase the number of iterations How do I install opencv using pip? Access IP Camera in Python OpenCV ImportError: libSM.so.6: cannot open shared object file: No such file or directory Convert np.array of type float64 to type uint8 scaling values How to import cv2 in python3? cmake error 'the source does not appear to contain CMakeLists.txt'

Examples related to pycharm

"UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website Pycharm/Python OpenCV and CV2 install error Import numpy on pycharm Global npm install location on windows? Pycharm and sys.argv arguments PyCharm error: 'No Module' when trying to import own module (python script) Using (Ana)conda within PyCharm Error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat) when running Python script How to run PyCharm in Ubuntu - "Run in Terminal" or "Run"?