Install OpenCV 3.4 in Python 3.7 / 2.7

1 minute read

OpenCV 3 works with Python 2.7, 3.4, 3.5, 3.6 and 3.7. The unofficial OpenCV PyPi wheels work for Linux, Mac and Windows.

pip install OpenCV for Python

Importantly, the pip install methods below also work for the OpenCV GUI such as imshow etc.

python -m pip install opencv-python

ARM / Raspberry Pi

python -m pip install opencv-python

also works for certain ARM platforms like the Raspberry Pi. Note: If you install on an ARMv7 Raspberry Pi (or ARMv8 running in ARMv7 e.g. with Raspbian), you will need to pip uninstall and pip install upon inserting the SD card into an ARMv6 system, or

SIGILL Illegal Instruction

error will result. An example of this is setting up a Python OpenCV algorithm on a Raspberry Pi 2/3/3+, then inserting the same SD card into a Raspberry Pi 0/0W/1 will require reinstalling OpenCV–this is trivial and fast to do.

OpenCV with extra contribs

For those desired the latest extended functionality that hasn’t yet been incorporated into the core package, OpenCV including the Extra contributed modules may be obtained by:

python -m pip install opencv-contrib-python

Notes

  • OpenCV 3 release notes
  • Conda-forge OpenCV 3
  • (reference) Windows-only OpenCV wheels. (cpMN where you have Python M.N). contrib includes OpenCV-extra packages. For example, assuming you have Python 3.7, you might download opencv_python-3.4.3+contrib-cp37-cp37m-win_amd64.whl.

Python executable selection

If you get the ... is not supported on this platform error be sure you’re not accidentally using Python 2.7 instead of Python 3, you may have to manually specify the path for the pip command e.g.

c:\anaconda3\scripts\python -m pip install opencv-python

Test Python OpenCV install

We made several test scripts to try out the OpenCV install.

compile source

You can compile and install OpenCV for Python. Or compile OpenCV with extra contributed packages. Compiling yourself allows customizing and optimizing OpenCV for your computer (e.g. using GPU, TBB, OpenCL, etc.).

conda

The conda install opencv and conda install -c conda-forge opencv methods for OpenCV continue to be BROKEN for video/image reading and display. Use pip install above instead.

Leave a comment