Opencv version check

Opencv version check DEFAULT


OpenCV on Wheels

Pre-built CPU-only OpenCV packages for Python.

Check the manual build section if you wish to compile the bindings from source to enable additional modules such as CUDA.

Installation and Usage

  1. If you have previous/other manually installed (= not installed via ) version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages), remove it before installation to avoid conflicts.

  2. Make sure that your version is up-to-date (19.3 is the minimum supported version): . Check version with . For example Linux distributions ship usually with very old versions which cause a lot of unexpected problems especially with the format.

  3. Select the correct package for your environment:

    There are four different packages (see options 1, 2, 3 and 4 below) and you should SELECT ONLY ONE OF THEM. Do not install multiple different packages in the same environment. There is no plugin architecture: all the packages use the same namespace (). If you installed multiple different packages in the same environment, uninstall them all with and reinstall only one package.

    a. Packages for standard desktop environments (Windows, macOS, almost any GNU/Linux distribution)

    • Option 1 - Main modules package:
    • Option 2 - Full package (contains both main modules and contrib/extra modules): (check contrib/extra modules listing from OpenCV documentation)

    b. Packages for server (headless) environments (such as Docker, cloud environments etc.), no GUI library dependencies

    These packages are smaller than the two other packages above because they do not contain any GUI functionality (not compiled with Qt / other GUI components). This means that the packages avoid a heavy dependency chain to X11 libraries and you will have for example smaller Docker images as a result. You should always use these packages if you do not use et al. or you are using some other package (such as PyQt) than OpenCV to create your GUI.

    • Option 3 - Headless main modules package:
    • Option 4 - Headless full package (contains both main modules and contrib/extra modules): (check contrib/extra modules listing from OpenCV documentation)
  4. Import the package:

    All packages contain Haar cascade files. can be used as a shortcut to the data folder. For example:

  5. Read OpenCV documentation

  6. Before opening a new issue, read the FAQ below and have a look at the other issues which are already open.

Frequently Asked Questions

Q: Do I need to install also OpenCV separately?

A: No, the packages are special wheel binary packages and they already contain statically built OpenCV binaries.

Q: Pip install fails with ?

Since version 4.3.0.*, wheels were replaced by wheels. If your pip is too old, it will try to use the new source distribution introduced in to manually build OpenCV because it does not know how to install wheels. However, source build will also fail because of too old because it does not understand build dependencies in . To use the new pre-built wheels (or to build from source), your version must be >= 19.3. Please upgrade with .

Q: Import fails on Windows: ?

A: If the import fails on Windows, make sure you have Visual C++ redistributable 2015 installed. If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.

Windows N and KN editions do not include Media Feature Pack which is required by OpenCV. If you are using Windows N or KN edition, please install also Windows Media Feature Pack.

If you have Windows Server 2012+, media DLLs are probably missing too; please install the Feature called "Media Foundation" in the Server Manager. Beware, some posts advise to install "Windows Server Essentials Media Pack", but this one requires the "Windows Server Essentials Experience" role, and this role will deeply affect your Windows Server configuration (by enforcing active directory integration etc.); so just installing the "Media Foundation" should be a safer choice.

If the above does not help, check if you are using Anaconda. Old Anaconda versions have a bug which causes the error, see this issue for a manual fix.

If you still encounter the error after you have checked all the previous solutions, download Dependencies and open the (located usually at ) file with it to debug missing DLL issues.

Q: I have some other import errors?

A: Make sure you have removed old manual installations of OpenCV Python bindings ( or cv2.pyd in site-packages).

Q: Function foo() or method bar() returns wrong result, throws exception or crashes interpriter. What should I do?

A: The repository contains only OpenCV-Python package build scripts, but not OpenCV itself. Python bindings for OpenCV are developed in official OpenCV repository and it's the best place to report issues. Also please check {OpenCV wiki]( and the fficial OpenCV forum before file new bugs.

Q: Why the packages do not include non-free algorithms?

A: Non-free algorithms such as SURF are not included in these packages because they are patented / non-free and therefore cannot be distributed as built binaries. Note that SIFT is included in the builds due to patent expiration since OpenCV versions 4.3.0 and 3.4.10. See this issue for more info:

Q: Why the package and import are different (opencv-python vs. cv2)?

A: It's easier for users to understand than and it makes it easier to find the package with search engines. (old interface in old OpenCV versions was named as ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet. Changing the import name or behaviour would be also confusing to experienced users who are accustomed to the .

Documentation for opencv-python

AppVeyor CI test status (Windows)Travis CI test status (Linux and macOS)

The aim of this repository is to provide means to package each new OpenCV release for the most used Python versions and platforms.

CI build process

The project is structured like a normal Python package with a standard file. The build process for a single entry in the build matrices is as follows (see for example file):

  1. In Linux and MacOS build: get OpenCV's optional C dependencies that we compile against

  2. Checkout repository and submodules

    • OpenCV is included as submodule and the version is updated manually by maintainers when a new OpenCV release has been made
    • Contrib modules are also included as a submodule
  3. Find OpenCV version from the sources

  4. Build OpenCV

    • tests are disabled, otherwise build time increases too much
    • there are 4 build matrix entries for each build combination: with and without contrib modules, with and without GUI (headless)
    • Linux builds run in manylinux Docker containers (CentOS 5)
    • source distributions are separate entries in the build matrix
  5. Rearrange OpenCV's build result, add our custom files and generate wheel

  6. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly

  7. Install the generated wheel

  8. Test that Python can import the library and run some sanity checks

  9. Use twine to upload the generated wheel to PyPI (only in release builds)

Steps 1--4 are handled by .

The build can be customized with environment variables. In addition to any variables that OpenCV's build accepts, we recognize:

  • . Set to to emulate the CI environment build behaviour. Used only in CI builds to force certain build flags on in . Do not use this unless you know what you are doing.
  • and . Set to to build the contrib and/or headless version
  • , Set to to enable the Java client build. This is disabled by default.
  • . Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.

See the next section for more info about manual builds outside the CI environment.

Manual builds

If some dependency is not enabled in the pre-built wheels, you can also run the build locally to create a custom wheel.

  1. Clone this repository:
    • you can use to checkout some other version of OpenCV in the and submodules if needed
  2. Add custom Cmake flags if needed, for example: (in Windows you need to set environment variables differently depending on Command Line or PowerShell)
  3. Select the package flavor which you wish to build with and : i.e. if you wish to build
  4. Run . NOTE: make sure you have the latest version, the command replaces the old command which does not support .
    • this might take anything from 5 minutes to over 2 hours depending on your hardware
  5. You'll have the wheel file in the folder and you can do with that whatever you wish
    • Optional: on Linux use some of the images as a build hosts if maximum portability is needed and run for the wheel after build
    • Optional: on macOS use (same as but for macOS) for better portability

Manual debug builds

In order to build in an unoptimized debug build, you need to side-step the normal process a bit.

  1. Install the packages and via pip.
  2. Run the command .
  3. Install the generated wheel file in the folder with .

If you would like the build produce all compiler commands, then the following combination of flags and environment variables has been tested to work on Linux:

See this issue for more discussion:

Source distributions

Since OpenCV version 4.3.0, also source distributions are provided in PyPI. This means that if your system is not compatible with any of the wheels in PyPI, will attempt to build OpenCV from sources. If you need a OpenCV version which is not available in PyPI as a source distribution, please follow the manual build guidance above instead of this one.

You can also force to build the wheels from the source distribution. Some examples:

    If you need contrib modules or headless version, just change the package name (step 4 in the previous section is not needed). However, any additional CMake flags can be provided via environment variables as described in step 3 of the manual build section. If none are provided, OpenCV's CMake scripts will attempt to find and enable any suitable dependencies. Headless distributions have hard coded CMake flags which disable all possible GUI dependencies.

    On slow systems such as Raspberry Pi the full build may take several hours. On a 8-core Ryzen 7 3700X the build takes about 6 minutes.


    Opencv-python package (scripts in this repository) is available under MIT license.

    OpenCV itself is available under Apache 2 license.

    Third party package licenses are at LICENSE-3RD-PARTY.txt.

    All wheels ship with FFmpeg licensed under the LGPLv2.1.

    Non-headless Linux and MacOS wheels ship with Qt 5 licensed under the LGPLv3.

    The packages include also other binaries. Full list of licenses can be found from LICENSE-3RD-PARTY.txt.


    script searches for the version information from OpenCV sources and appends also a revision number specific to this repository to the version string. It saves the version information to file under in addition to some other flags.


    A release is made and uploaded to PyPI when a new tag is pushed to master branch. These tags differentiate packages (this repo might have modifications but OpenCV version stays same) and should be incremented sequentially. In practice, release version numbers look like this:


    The master branch follows OpenCV master branch releases. 3.4 branch follows OpenCV 3.4 bugfix releases.

    Development builds

    Every commit to the master branch of this repo will be built. Possible build artifacts use local version identifiers:


    These artifacts can't be and will not be uploaded to PyPI.

    Manylinux wheels

    Linux wheels are built using manylinux2014. These wheels should work out of the box for most of the distros (which use GNU C standard library) out there since they are built against an old version of glibc.

    The default images have been extended with some OpenCV dependencies. See Docker folder for more info.

    Supported Python versions

    Python 3.x compatible pre-built wheels are provided for the officially supported Python versions (not in EOL):

    Backward compatibility

    Starting from 4.2.0 and 3.4.9 builds the macOS Travis build environment was updated to XCode 9.4. The change effectively dropped support for older than 10.13 macOS versions.

    Starting from 4.3.0 and 3.4.10 builds the Linux build environment was updated from to . This dropped support for old Linux distributions.


    Find OpenCV Version Installed on Ubuntu [duplicate]

    1) Direct Answer: Try this:

    For me, I get:

    To see the version, you can try:


    2) Better Answer:

    "sudo make install" is your enemy, don't do that when you need to compile/update the library often and possibly debug step through it's internal functions. Notice how my config file is in a local build directory, not in /usr/something. You will avoid this confusion in the future, and can maintain several different versions even (debug and release, for example).

    Edit: the reason this questions seems to arise often for OpenCV as opposed to other libraries is that it changes rather dramatically and fast between versions, and many of the operations are not so well-defined / well-constrained so you can't just rely on it to be a black-box like you do for something like libpng or libjpeg. Thus, better to not install it at all really, but just compile and link to the build folder.

    answered Jan 10 '12 at 14:20

    peter karasevpeter karasev

    2,42611 gold badge2727 silver badges3838 bronze badges

    1. Subaru emblem
    2. Thomaston town clerk
    3. Craft banners minecraft

    How to Install OpenCV for Python on Windows?

    Prerequisite:Python Language Introduction
    OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human. When it integrated with various libraries, such as Numpuy, python is capable of processing the OpenCV array structure for analysis. To Identify image patterns and its various features we use vector space and perform mathematical operations on these features.

    To install OpenCV, one must have Python and PIP, preinstalled on their system. To check if your system already contains Python, go through the following instructions:

     Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

    To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

    Open the Command line(search for cmd in the Run dialog(+ R).
    Now run the following command:

    python --version

    If Python is already installed, it will generate a message with the Python version available.

    If Python is not present, go through How to install Python on Windows? and follow the instructions provided.
    PIP is a package management system used to install and manage software packages/libraries written in Python. These files are stored in a large “on-line repository” termed as Python Package Index (PyPI).
    To check if PIP is already installed on your system, just go to the command line and execute the following command:

    pip -V

    Verification of pip

    If PIP is not present, go through How to install PIP on Windows? and follow the instructions provided.

    Downloading and Installing OpenCV:

    OpenCV can be directly downloaded and installed with the use of pip (package manager). To install OpenCV, just go to the command-line and type the following command:

    pip install opencv-python

    Beginning with the installation:

    To check if OpenCV is correctly installed, just run the following commands to perform a version check:

    python >>>import cv2 >>>print(cv2.__version__)


    Build and Install OpenCV With CUDA GPU Support on Windows 10 - OpenCV 4.5.1 - 2021

    Introduction and Overview

    This document contains instructions for installing and migrating to the latest release of OpenCV (version 3) and the Python bindings. In addition to some API changes, there are also changes to the Python interface (e.g. removal of ) that may require changes in existing code to work with the new version of the module. After installation, see the next page, Migration & Changes, for details regarding the changes to the module and for help migrating existing Python code to the new version.

    This page covers installing OpenCV 3 on Windows (using pre-built binaries) and Linux (compiled from source), including the Python interface (the module). OpenCV can be downloaded from the official OpenCV website. Note that this guide is written based on OpenCV version 3.1.0. After installation, it is recommended that you can check the version of OpenCV that Python is using:

    Note that although OpenCV 3 is the latest release, by convention, the module is still named .

    Installing on Windows (pre-built binaries)

    Using pre-built binaries is the quickest way to get a Python OpenCV environment up and running on Windows. Currently, only the Python 2 version of the module is built and included in the latest Windows release. Support for Python 3 (as well as adding other non-standard features/modules), requires compiling from source - see the official OpenCV documentation for details.

    Downloading OpenCV and Python

    To begin, download OpenCV for Windows (version 3.1, ), and extract it to a directory of your choice. The Windows build includes both a 32-bit and 64-bit module for Python 2.7.

    Before continuing, ensure that you have a working Python 2.7 installation, which can be downloaded from the Python website. This guide was tested using Python 2.7.9 (x86 installer / x64 installer). When installing, it is recommended that you allow the installer to add Python to your environment variable, so you can run and from a command prompt.

    Installing Module Dependencies

    The Python OpenCV module requires both the and stack. To get this, first ensure that you have a working environment, and have installed (if not, use the links above, and ensure the Python folder is in your variable).

    Christoph Gohlke currently provides some (unofficial) pre-built Python packages for Windows, including NumPy and SciPy. Download the latest stable versions of NumPy and SciPy, and install them by calling from a command prompt. Note that you should download the version corresponding to your Python environment (2.7 in this case) and word length. For example, on 32-bit systems/interpreters:

    And for 64-bit systems/interpreters:

    After installing, you should be able to run and from a Python interpreter to verify that the modules were installed correctly. You can check what versions of NumPy and SciPy are installed from and , respectively.

    Installing Python-OpenCV Module

    Lastly, we need to copy the OpenCV module into the local Python packages. In the files extracted from , go to the folder , and open either the (for 32-bit) or (for 64-bit) folder. In each, there will be a file.

    Copy directly into the directory of your Python installation. For most users, this will be found at:

    Lastly, ensure that the OpenCV .dll files are somewhere in your system's , especially the (or for 64-bit systems) file required for loading video files.

    Continue on to the Verifying Installation section to ensure everything was installed correctly, and the new version of OpenCV is being used. Also be sure to check out the next page, Migration & Changes, for details about the changes to the module and updating existing code.

    Installing on Linux (compiling from source)

    Although this guide is written for Ubuntu 12.04/14.04 and other variants (e.g. Xubuntu/Lubuntu/Kubuntu), the process should largely be the same on other versions, as well as similar Debian-like Linux distributions. Pay attention to the output of each command to ensure everything worked correctly, and if there are any issues during the build process, see the bottom of this document for possible mitigations

    Downloading OpenCV

    To begin, download OpenCV for Linux (version 3.1.0, ), and extract it to a directory of your choice (e.g. ). Create a folder inside the folder where the archive was extracted (the directory containing the file), and open a terminal session there. For example:

    Execute all of following commands from the sub-folder itself, so the compiled files will be placed there.

    Installing Build Dependencies

    To compile OpenCV, we must ensure that the required dependencies are available, including the build tools themselves. We can get the required ones using on Ubuntu, but first, ensure the package list is up-to-date by running . Next, execute the following commands to get the required packages (see below for a one-line list of all):

    In single line:

    Note that for additional OpenCV modules/features (e.g. GPU/CUDA support, or Python 3 module), you will need to download the respective development/SDK packages for those libraries as well. The dependencies listed above only cover building OpenCV itself and the Python 2.7 module.

    Compiling and Installing OpenCV

    Now that we have the required build dependencies, run (again, in the directory we created) to generate the Makefile to build OpenCV:

    If there are any errors, ensure that you downloaded all the required packages - the output should help track down what is missing. To ensure the Python module will be built, you should see in the list of configured modules after running :

    If you do not see the module listed, in the "To be built" list, check that you have the proper Python development packages installed, remove all files from the folder, and try running the command again.

    Now, we can build OpenCV (and the Python module) using , and install it to our system:

    Ensure that the build was successful after calling , and check the output before installing. If you run into build issues/errors, again ensure that you have all the required dependencies and header files on your system. If there are actual build issues with OpenCV itself, see the Linux Build Issues section below for some possible workarounds.

    When installing OpenCV 3.0-rc1 on Ubuntu 12.04, I ran into build errors regarding some missing codec entries. As mentioned, the steps to do this are detailed below should you run into the same problem (the problem should be solved in version 3.1.0 and above). Ubuntu 14.04 and above should build successfully without requiring any modifications.

    If the build was successful, but you can't from a Python shell after running , you can install the module manually by copying the file we just built in the folder to . From the folder, this can be done by:

    After this step, the module is installed, and can now be imported by your Python environment. Continue on to the Verifying Installation section to ensure everything was installed correctly, and more importantly, that the correct version of OpenCV is being used by Python. You can also check out the next page, Migration & Changes, for details about changes to the module, and what changes need to be made to existing code to run with the updated module.

    Verifying Installation

    As mentioned previously, you can verify that the module was installed correctly by executing the following in a Python shell:

    If the correct version string is printed ( or newer if you used a more recent version), everything is installed correctly at this point!

    Note that there are some major changes to the module hierarchy itself, and Python programs written with OpenCV 2.4.x in mind may not work properly anymore. See the next section, Migration & Changes for details about the changes, and how to modify programs to deal with the changes.

    Linux Build Issues

    On some systems you may run into issues when compiling OpenCV itself, depending on what packages are available. If the proper header files are available, but build issues still arise, try to see if there are any workarounds below for the problem.

    Undefined in

    If you run into an issue where build errors are caused by certain codecs not being defined, you can download a more recent version of from here, and replace it in the source code you downloaded/extracted in the folder.

    Alternatively, you can declare them manually by editing the file itself by adding the missing codec entry for , and renaming to . You can see what changes have to be made by viewing this commit from the OpenCV GitHub project.

    Once the file is updated, you can call again from the folder, and OpenCV should finish compiling without error now.


    Version check opencv


    In this short tutorial, we will check how to obtain the version of the Python OpenCV module we have installed in our machine.

    We will do it by writing a very simple Python script which will import the module and then access its__version__ attribute. You can read more about this attribute here.

    Being able to obtain the OpenCV version installed might be important, for example, to confirm that we have access to a certain feature that is not implemented in older versions.

    The code shown below was tested using Python v3.7.2, on Windows 8.1.

    The code

    As already mentioned, we will obtain the version of the OpenCV module using a very simple script. The first thing we will do is importing the cv2 module.

    Then, we will print the value of the __version__ attribute of the module. This should output the OpenCV version.

    The final script can be seen below.

    import cv2 print(cv2.__version__)

    Testing the code

    To test the code, simply run it on an environment of your choice. In my case I’ll be using IDLE, a Python IDE. Note that I’m assuming you have the OpenCV module installed.

    You should get an output similar to figure 1. As can be seen, the image shows the version of my OpenCV installation. In my case, I have version 4.0.0.

    Naturally, depending on the version you have installed on your machine, the actual version printed might differ.

    Obtaining Python OpenCV version installed.

    Related Posts

    How to Check Version Of OpenCV


    Similar news:


    1243 1244 1245 1246 1247