Skip to content

Tutorials

How to install Python 3 and Opencv 4 on Windows

We’re going to see in this tutorial how to install Python 3 and Opencv 4 on Windows.

Here below you see a list of the steps necessary for a complete installation. If you have any problem following the steps, I suggest you to watch the video tutorial above that will guide you trough it step by step.

Install Python 3:

We pick Python 3.6.8 which at the moment I’m writing this article (march 2019) is the best supported version by the other external libraries needed for computer vision.

  1. Download Python 3.6.8 from this link.
  2. Run the installation file.
  3. On the installation file remember to stick “Add Python 3.6 to PATH”.
  4. Click on “Install Now” and go ahead until you see the message “Setup was successful”.

Install Opencv 4:

  1. Download the Opencv binary files here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
  2. Choose the compatible version of Opencv to your Python. We’ll download the latest version of Opencv (4.1) for Python 3.6.8.
    How to understand the right version?
    -cp37m-win32.whl means that Opencv is for python 3.7 (32 bit version)
    -cp36m-win_amd64.whl means that Opencv is for python 3.6 (64 bit version)

  3. Run the “Command Prompt” of Windows. You can type “CMD” on the sarch bar to find it.
  4. Go to the directory where the Opencv binaries that you downloaded is located.
    cd YOURPATHfor example in my case:
    cd C:\Users\pinolo\Downloads
  5. Now let’s install the Opencv module using PIP.
    python pip -m install opencv_python‑4.0.1+contrib‑cp37‑cp36m‑win_amd64.whl
  6. Now let’s install Numpy using PIP.
    python pip -m install numpy
  7. The installation is complete. Now we can test it by running python and importing the libraries cv2 (for opencv) and numpy. If we don’t get any error it means that it has been installed successfully.


28 comments

    1. Actually OpenCV is not an executable application with a GUI. Rather it is a library for Python and C++ and other languages.
      So basically, you can import opencv library into your Python code and use it. For OpenCV commands and keywords to use in Python, you can refer OpenCV documentations.
      There are many tutorials in pysource.com , https://www.tutorialspoint.com/opencv/index.htm , https://www.pyimagesearch.com/2018/07/19/opencv-tutorial-a-guide-to-learn-opencv/ , https://pythonprogramming.net/loading-images-python-opencv-tutorial/ and lot more.

      I hope I got you correctly.

      Thanks

  1. Only this worked for me
    python -m pip install opencv_python‑4.0.1+contrib‑cp37‑cp36m‑win_amd64.whl

    not this
    python pip -m install opencv_python‑4.0.1+contrib‑cp37‑cp36m‑win_amd64.whl

  2. C:\Users\Lyall\Downloads\opencv\build\python\cv2
    I have got this file on my computer but when i ask cmd admin to “import cv2” it comes back “no module named ‘cv2’
    yet here it is in my files??? how do i proceed?

  3. Hi Sergio. How can I use Pycharm after this? Do I need to install OpenCV again or should I add it somehow?
    It would be great if you could provide an example.
    Thanks!!!

  4. Hii, may i know is there any different of features for the installed opencv using this method and the cmake method ? Glad to have you answer my question, i am new to these things.

  5. Hi! I want to develop a look-based media player(if a face detects video play else pause ), volume and next/previous are controlled through hand gesture. I want to use python and c# languages. What tools should I use and how I can connect python andC#? plz, guide me from start. thnx in advance

  6. >>> import cv2
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: DLL load failed: The specified module could not be found.
    i got this error while importing cv2.

Join the discussion