91

I know that I could pip install opencv-python which installs opencv3, but is there a separate command or name for opencv specific version such as 2.4.9?

If not, how can I specify which version to install?

Thanks.

Jerry Chong
  • 7,954
  • 4
  • 45
  • 40
matchifang
  • 5,190
  • 12
  • 47
  • 76

12 Answers12

125

Via pip you can specify the package version to install using the following:

pip install opencv-python==2.4.9

However, that package does not seem to be available on pypi.

A little trick for checking available versions:

pip install opencv-python==

Which returns:

Could not find a version that satisfies the requirement opencv-python== (from versions: 3.1.0.0, 3.1.0.1, 3.1.0.2, 3.1 .0.3, 3.1.0.5, 3.2.0.6, 3.2.0.7) No matching distribution found for opencv-python==

etemple1
  • 1,748
  • 1
  • 11
  • 13
  • 2
    2.4.9 is not a matching requirement for the versions available to me. Ideas? – MonsieurBeilto Mar 14 '18 at 22:19
  • so how do we install opencv version 2 for python ? – Scott Yang Nov 13 '18 at 07:30
  • Doing what you say results in the following error: Could not find a version that satisfies the requirement opencv-python==2.4.9 (from versions: 3.1.0.5, 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, 3.4.0.12, 3.4.0.14, 3.4.1.15, 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19) No matching distribution found for opencv-python==2.4.9 – Employee Dec 01 '18 at 13:26
  • or if you want to see latest version `sudo apt-cache policy opencv-python` – Josh Aug 08 '19 at 14:36
42

Easy and simple

  • Prerequisites
    • pip install matplotlib
    • pip install numpy
  • Final step
    • pip install opencv-python

Specific version * Final step * opencv-python==2.4.9

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Abdul Sheikh
  • 547
  • 4
  • 6
  • 1
    Why would someone downvote this ?! doesn't it actually work? I'll upvote this. – Mehran Jan 22 '18 at 09:43
  • People do not understand that I'm simply trying to help. – Abdul Sheikh Jan 22 '18 at 16:38
  • 3
    I didn't downvote, but I can explain why others might have: You're answer is suggesting exactly what the question states didn't work: `pip install opencv-python`. Therefore this is not answering the question (how to install OpenCV version 2.4.9 (or similar), not the latest version). However the question title obviously will lead people here who want to use the module cv2 (which is included in any OpenCV version > 2.0, also 3.4) and for those you provided the most straightforward way... therefore it arguably is still a good answer, at least to the question title ;) – Honeybear Feb 21 '18 at 16:28
  • 4
    @AbdulSheikh when I type `pip install opencv-python==3.6.4` it throws an error `Could not find a version that satisfies the requirement opencv-python==3.6.4 (from versions: 3.1.0.5, 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, 3.4.0.12) No matching distribution found for opencv-python==3.6.4` – bit_scientist Apr 10 '18 at 01:17
15

There's another easy way, you can type in terminal

sudo apt-get install python-opencv

Install OpenCV-Python in Ubuntu

After installing it, you can use opencv version 2.4 in both c++ and python.

But I recommend you should use opencv 3.2.0 and opencv-contrib, it gives more features

Hope this can help!

Santhosh
  • 1,554
  • 1
  • 13
  • 19
Vinh Trieu
  • 993
  • 8
  • 12
  • Some distributions have ppa of opencv, some did not. You must add PPA of opencv base on your OS distribution in order to install this. Or you can install Anaconda to resolve this. It has OpenCV 3.2.0 – Vinh Trieu Jan 15 '18 at 07:52
  • Try this `sudo apt-get install python-opencv` – Santhosh Mar 07 '18 at 11:43
  • This does not work anymore as it will install opencv 3.2.0 – abggcv Aug 18 '19 at 16:24
  • may be your distribution is upgraded, so that it can only find 3.2.0. Or you could install anaconda instead – Vinh Trieu Aug 20 '19 at 11:31
9

cv2 vs. "opencv3"

To get a potential misunderstanding out of the way: The python OpenCV module is named and imported via import cv2 in all versions > 2.0, including > 3.0. If you want to work with cv2, installing OpenCV versions > 3 is fine - unless you're looking for specific compatibility with older versions or are a fan of the 2.4.x versions. The switch from 2.4.x to 3.x was in 2015 and in terms of features, speed and transparency, it makes much sense to use the newer versions. You can read here and here about major differences. 2.4.x versions are still supported though, current release is 2.4.13.5.

Installing a specific version, e.g. OpenCV 2.4.9

That said: If you want to install a specific version that neither pip install opencv-python==2.4.X, sudo apt-get install opencv nor conda install opencv=2.4.x provide (as explained by other answers here), you can always install from sources. In the sourceforge repository you can find all major versions for each operating system. Although for unxeperienced users this might be scary, it is well explained in some tutorials. E.g. here for 2.4.9 on Ubuntu 14.04. Or here is the official Linux install doc for the latest release 2.4.13.5.

In essence, the install process boils down to:

  1. install dependencies, refer to docs (e.g. here) for required packages

  2. get sources from OpenCVs sourceforge

    e.g. wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip

  3. unzip sources and prepare build by creating build directory and running cmake

    mkdir build
    cd build
    cmake (... your build options ...)
    
  4. build in the created build directory with:

    make
    sudo make install
    
Honeybear
  • 2,928
  • 2
  • 28
  • 47
6

You can also do it using Anaconda:

conda install -c https://conda.binstar.org/menpo opencv=2.4.9
Archie
  • 2,247
  • 1
  • 18
  • 35
  • However, this version requires libpng 1.5.x while conda only provides libpng>1.6.x now. – fytao Mar 03 '20 at 08:19
5

If you are using windows os, you can download your desired opencv unofficial windows binary from here, and type something like pip install opencv_python-2.4.13.2-cp27-cp27m-win_amd64.whl in the directory of binary file.

kai06046
  • 292
  • 1
  • 3
  • 10
3

you can try this

pip install opencv==2.4.9
Rhythm sharma
  • 118
  • 1
  • 8
  • That will install the latest release of the package, rather than OpenCV 2. The command was also already mentioned by the OP. – E_net4 Nov 23 '18 at 11:17
  • i tried this command and i get following error Collecting opencv==2.4.9 Could not find a version that satisfies the requirement opencv==2.4.9 (from versions: ) No matching distribution found for opencv==2.4.9 – Azam Rafique Dec 24 '18 at 07:55
  • @AzamRafique try a python distributor, i personally recommend Anaconda. – Rhythm sharma Dec 27 '18 at 05:54
2
python3.6 -m pip install opencv-python

will install cv2 in linux in branch python3.6

vishal
  • 855
  • 1
  • 8
  • 16
2
python -m pip install opencv-python

which will install opencv based on your current python

tech-gayan
  • 1,373
  • 1
  • 10
  • 25
1

If you're a Windows user, opencv can be installed using pip, like this:

pip install opencv-python==<python version>

ex - pip install opencv-python==3.6

If you're a Linux user:

sudo apt-get install python-opencv

At the same time, opencv can be installed using conda like this...

conda install -c https://conda.binstar.org/menpo opencv=3.6
Moffee
  • 401
  • 5
  • 15
Gayan Sampath
  • 163
  • 2
  • 5
0

Below Python packages are to be downloaded and installed to their default locations.

1.1. Python-2.7.x.

1.2. Numpy.

1.3. Matplotlib (Matplotlib is optional, but recommended since we use it a lot in our tutorials).

Install all packages into their default locations. Python will be installed to C:/Python27/.

After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.

Download latest OpenCV release from sourceforge site and double-click to extract it.

Goto opencv/build/python/2.7 folder.

Copy cv2.pyd to C:/Python27/lib/site-packeges.

Open Python IDLE and type following codes in Python terminal.

import cv2 print cv2.version If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html

amit ghosh
  • 81
  • 7
0

The following command line pip install opencv-python==3.4.2.16 works properly. Use one of the versions presented to you. May be:

3.1.0.5, 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, or 3.4.0.12, etc.

To make sure, you can see my screenshot.screenshot