Chris Conlan

Data Scientist

  • About
  • Blog
    • Business Management
    • Programming with Python
    • Programming with R
    • Automated Trading
    • 3D Technology and Virtual Reality
  • Books
    • Fast Python
    • Algorithmic Trading with Python
    • The Blender Python API
    • Automated Trading with R
  • Snippets
  • Opportunities

Install Python OpenCV 3 on Windows with Anaconda Environments

May 31, 2017 By Chris Conlan 50 Comments

Recently, Satya Mallick, founder of learnopencv.com, posted an impressive (but complicated) method for installing OpenCV 3 on Windows that supports both the C++ and Python API’s. Since a lot of users will be interested in solely Python OpenCV, I figured it would be helpful to post a relatively quick method for getting Python OpenCV 3 up and running on Windows.

1) Install Anaconda

Head over to continuum.io/downloads/ and install the latest version of Anaconda. Make sure to install the “Python 3.6 Version” for the appropriate architecture. Install it with the default settings.

2) Open the Anaconda Prompt

Anaconda installs a few programs on your computer when you run the installer. These include the Anaconda Navigator, Anaconda Cloud, Spyder, and the Anaconda Prompt. Search in your Windows taskbar for the Anaconda Prompt. This is a modified version of the Windows Command Prompt that support specific Anaconda commands. All of the code we discuss in these instructions will be run directly in the Anaconda Prompt.

To test the Anaconda Prompt, run:

conda --version

3) Create an Anaconda Environment

This section is essentially a Windows distillation of https://conda.io/docs/using/envs.html#create-an-environment.

Anaconda environments are similar to a Python virtualenv, except they use Anaconda’s superb package managers. When we install OpenCV 3, we will do so in an Anaconda environment that uses specifically Python 3.5, and that version of Python will only be accessible through the environment. Below are some basics of Anaconda environment management.

### Basics of Anaconda environment management ###
# Creating an environment
conda create --name myNewEnv python=x.x.x


# Activating an environment
activate myNewEnv

# Deactivating an environment
deactivate myNewEnv

# Listing environments
conda info --envs

# Removing an environment
conda remove --name myNewEnv --all

Run the following to create and activate a new Anaconda environment for Python 3.5. We use Python 3.5 for compatibility with the OpenCV 3 distribution we will be using.

conda create --name myWindowsCV python=3.5
activate myWindowsCV

Now, you should see “(myWindowsCV)” prepended to the command line. When the environment’s name is prepended to the command line, the environment is active, and Anaconda has modified the $PATH variables of the console to point to various directories in anaconda3/envs/myWindowsCV. Running “python –version” should now return Python 3.5.* as opposed to your system Python version.

(myWindowsCV) C:\Users\Chris>python --version
Python 3.5.2 :: Continuum Analytics, Inc.

4) Install OpenCV 3 and Dependencies

In the Anaconda Prompt, with your Anaconda environment active, run:

conda install numpy
conda install anaconda-client
conda install --channel https://conda.anaconda.org/menpo opencv3

Now, enter Python and check that OpenCV 3 is installed.

(myWindowsCV) C:\Users\Chris>python
>>>import cv2
>>>cv2.__version__
'3.1.0'

5) Start Using Python and OpenCV3

Always make sure your environment is active, or you will not be accessing the correct Python version. Managing virtual environments can be cumbersome for users that prefer heavyweight IDE’s like Eclipse or PyCharm, but these issues are well-documented by Anaconda: IDE Integration.

This setup is ideal for users that:

  • Need to ensure cross-OS compatibility (Anaconda can be installed on MacOS and Linux)
  • Are interested in pure Python implementations of OpenCV
  • Are interested in highly stable releases of OpenCV 3 and Python 3
  • Prefer light text editors for programming
  • Have experience configuring heavier IDE’s

System Specs

This setup was tested on Windows 10 and Windows 8.1 computers. Comment below with any issues and we will see if we can’t work through them.

Filed Under: Computer Vision, Programming with Python

Comments

  1. Michael Brown says

    July 23, 2017 at 2:49 am

    Hi Chris,

    Thanks for the tutorial, I’ve been trying for hours to get opencv to work through various other sources, and from your tutorial, I think I’m almost there.

    I get to the (myWindowsCV) C:\Users\Chris>python step, all goes well:

    “Python 3.5.3 |Continuum…for more information”

    >>>import cv2

    ImportantError: numpy.core.multiarray failed to import
    Traceback (most recent call last):
    File “”, line 1, in
    ImportantError: numpy.core.multiarray failed to import

    Before I started this I unistalled Anaconda and reinstalled. I would like to be able to use opencv in Spyder.

    Regrds,

    Mike

    Reply
    • Chris Conlan says

      July 23, 2017 at 2:54 am

      Hi Mike,

      Glad to help.

      Numpy is a dependency for OpenCV Python, so make sure you successfully installed it in the step above the one you referenced. After running “python” to enter the Python terminal, try:

      import numpy

      to verify you installed it correctly. If you still have trouble, you may want to investigate issues between your system and numpy. This issue may be magically solved by reducing the Python version to 3.4 or 3.3. Also, for the future, you rarely if ever need to reinstall Anaconda. It does a very good job of managing dependencies. So, if you mess up, just start over from the Anaconda Prompt steps.

      Best of luck,
      Chris

      Reply
      • naveen says

        August 31, 2018 at 1:28 am

        this was successfully installed

        import cv2
        cv2.version
        ‘3.1.0’
        my doubt is can i use it in jupiter notebook
        i mean importing the cv2 in jupiter notebook

        Reply
    • Chris Conlan says

      July 23, 2017 at 2:56 am

      Once you successfully import cv2 from the Python terminal, you should be able to configure your Spyder install to use the Anaconda environment that accomplished this.

      Reply
      • Harald Vaessin says

        September 29, 2017 at 7:48 pm

        I followed your installation and it works in the anaconda prompt, but Spyder is not able to import it. Any suggestions on how I can reconfigure it so that it can.

        Reply
        • Chris Conlan says

          September 29, 2017 at 9:27 pm

          I am not a Spyder user so I can’t say for sure. You’ll have to activate the environment via Spyder somehow. Any Spyder users out there with knowledge on this?

          Reply
          • Cal says

            October 26, 2017 at 11:24 am

            The problem is that openCV is installed to a different directory to Spyder’s modules. To fix this, copy the file
            C:\Users\~\Anaconda3\envs\myWindowsCV\lib\site-packages\cv2.cp35-win_amd64.pyd
            to
            C:\Users\~\Anaconda3\lib\site-packages\

            Spyder must then be launched from Anaconda Prompt with the myWindowsCV environment activated

            After copying in Anaconda Prompt type:

            >>> activate myWindowsCV
            >>> spyder

            In Spyder, cv2 should now be importable.

            If for whatever reason you are interested in locating the openCV module file you can use the __file__ attribute of the cv2 module in Anaconda Prompt.

            In Anaconda Prompt, activate your environment:
            C:\Users\~> activate myWindowsCV

            Next, run python:
            (myWindowsCV) C:\Users\~> python

            >>> import cv2
            >>> cv2.__file__

            This will print the location for the cv2 module.

            Hope that helps,
            C

          • Nazneen says

            January 27, 2018 at 1:09 pm

            I am no expert at this so maybe I was just lucky but when I faced the same problem, to get it working i installed spyder in the same environment. I did the following:

            In the Anaconda prompt:

            1. activate myWindowsCV
            (or whatever environment name you installed python 3.5 , numpy, open cv … with)
            2. conda install spyder
            3. spyder
            (To launch Spyder from Anaconda Prompt with the myWindowsCV environment activated)

            This worked for me. Wish you luck, it can test your patience!

        • Varjak says

          February 23, 2018 at 4:12 pm

          I don’t know anything about setting virtual environments with Anaconda nor the reason to do it. But what I did worked:
          – Search Anaconda in the windows search bar
          – Click Anaconda Prompt
          – Without setting a virtual environment ( (base) C:\Users\”UserX”> ) type:
          conda install -c conda-forge opencv
          – You will be asked for confirmation. Type “y”
          – After that, normally open Spyder and test if you have openCV by typing:
          >>>import cv2
          >>>cv2.__version__
          – Mine appears as ‘3.3.0’

          Hope it helps!

          Reply
          • Chris Conlan says

            February 26, 2018 at 7:38 pm

            Hi Varjak,
            This will work if your default Anaconda Python has a version compatible with OpenCV. I think compatibility between Python 3.6 and OpenCV 3.3 has recently been made available through Menpo. Thanks for sharing your solution.
            Best,
            Chris

  2. Mark Roger L. Cabadsan says

    August 25, 2017 at 7:03 am

    Is it still applicable in the latest version of anaconda?

    Reply
    • Mark Roger L. Cabadsan says

      August 25, 2017 at 9:13 am

      Every time I run conda install –channel “https://conda.anaconda.org/menpo opencv3”, it keeps on saying

      UnsatisfiableError: The following specifications were found to be in conflict:
      – opencv3 -> python 2.7*
      – python 3.6*
      Use “conda info ” to see the dependencies for each package.

      How do I fix this sir? I hope you can give me a hand.

      Reply
      • Chris Conlan says

        August 25, 2017 at 9:06 pm

        It looks like you attempted to install OpenCV 3 on top of a Python 3.6 environment. While Python 3.6 is the newest version officially supported by Anaconda, Anaconda also supports earlier versions of Python.

        In the above instructions, I mention that we want to install Python 3.5 instead of 3.6 to satisfy the dependencies of OpenCV 3. Make sure to specify “python=3.5” in your “conda create” command, and you won’t have that error when installing OpenCV 3.

        Best of luck,
        Chris

        Reply
      • Chris Conlan says

        September 7, 2017 at 9:06 pm

        ***See comment thread, 3.5 is required***
        Hi Mark, see the updated article. Python 3.5 is required for OpenCV 3 on Anaconda.

        Reply
        • Mags says

          September 12, 2017 at 12:53 am

          I was installing today and received the same error using 3.6. However, downgrading to 3.5 permitted the installation to complete.

          Reply
          • Mary says

            September 13, 2017 at 10:14 am

            I got the same error

        • Alessandro Bottoni says

          September 13, 2017 at 4:16 pm

          I was installing today and I had the same error. Python 3.5 is still required for Anaconda.

          Reply
          • dapurachmadilham says

            August 27, 2018 at 5:58 pm

            in environment i try this (myWindowsCV) :\Users\bobby> conda install -c anaconda spyder

            i got no error. My OS is windows 7

        • Chris Conlan says

          September 13, 2017 at 5:50 pm

          Ok… to further complicate things, 3.6 is required on my linux machines and 3.5 is required on my linux machines. Will update the article.

          Reply
  3. Yash says

    September 7, 2017 at 3:21 pm

    Hi,
    Can you please help me?
    I am facing the following error: –
    >>> import cv2
    RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: numpy.core.multiarray failed to import
    >>>

    Reply
    • Chris Conlan says

      September 7, 2017 at 7:37 pm

      Hi Yash,

      I’ve never seen that one. before. I encourage you to start from scratch with a new Anaconda environment and see if that helps, making sure to follow the instructions carefully. I have verified that this install works and Window 7, 8, and 10, recent MacOSX versions, Ubuntu, and RHEL/CentOS variants.

      Please list your system specs if you believe this to be a unique problem.

      Best,
      Chris

      Reply
  4. Gulsah says

    September 16, 2017 at 4:21 pm

    Hello,
    I need to implement opencv in my python 3.6. I use anaconda/spyder editor. I tried the step that you have mentioned and I get
    (myWindowsCV) C:\Users\gulsah.ayhan>python
    Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import cv2
    Traceback (most recent call last):
    File “”, line 1, in
    ModuleNotFoundError: No module named ‘cv2’
    >>> cv2.__version__
    Traceback (most recent call last):
    File “”, line 1, in
    NameError: name ‘cv2’ is not defined
    >>>
    errors after I tried your steps. What should I do? I dont know much about these topics so, I need a clear explanation.
    Thank you in advance,

    Gulsah.

    Reply
    • Chris Conlan says

      September 16, 2017 at 10:08 pm

      Hi Gulsah,
      You need to use Python 3.5 as the instructions state to get OpenCV to run on Windows.
      The Python 3.6 version of OpenCV for Anaconda only runs on UNIX at the moment.

      Reply
  5. M A Hassan says

    September 19, 2017 at 10:35 am

    Hello Chris

    I am a beginner to python; I’m in middle of migrating from MATLAB to python. Thus, I’m using spyder for programming. I tried installing opencv using the conda command prompt as you instructed. Thankyou!!!

    However, still, i am not able to import cv2 in spyder i keep getting the error

    import cv2
    Traceback (most recent call last):

    File “”, line 1, in
    import cv2

    ModuleNotFoundError: No module named ‘cv2’

    would greatly appreciate your assistance

    Reply
  6. Saurabh Zinjad says

    October 29, 2017 at 5:22 pm

    Hi Chris,

    Thanks for the tutorial, it’s really useful

    but I got one error called “PackageNotFoundError”

    when I run ” conda install –channel https://conda.anaconda.org/menpo opencv3″

    ================================================================
    (SBZEnv) C:\Users\Akash>conda install https://conda.anaconda.org/menpo opencv3
    Fetching package metadata ………….

    PackageNotFoundError: Packages missing in current channels:

    – https://conda.anaconda.org/menpo

    We have searched for the packages in the following channels:

    – https://repo.continuum.io/pkgs/main/win-32
    – https://repo.continuum.io/pkgs/main/noarch
    – https://repo.continuum.io/pkgs/free/win-32
    – https://repo.continuum.io/pkgs/free/noarch
    – https://repo.continuum.io/pkgs/r/win-32
    – https://repo.continuum.io/pkgs/r/noarch
    – https://repo.continuum.io/pkgs/pro/win-32
    – https://repo.continuum.io/pkgs/pro/noarch
    – https://repo.continuum.io/pkgs/msys2/win-32
    – https://repo.continuum.io/pkgs/msys2/noarch

    (SBZEnv) C:\Users\Akash>
    ===============================================================

    I think, files we want fetch from that site is no longer present OR maybe removed access

    regards,

    Saurabh

    Reply
    • Saurabh Zinjad says

      October 29, 2017 at 5:37 pm

      I found solution too,

      ======================================================
      conda install numpy
      conda install anaconda-client
      conda install –channel https://conda.anaconda.org/menpo opencv3
      =======================================================

      instead of
      “conda install –channel https://conda.anaconda.org/menpo opencv3″

      i execute command
      conda install -c menpo opencv3

      OpenCV 3 is installed.

      Reply
  7. Saifullah Khalid says

    November 12, 2017 at 3:28 pm

    Thanks, I was totally frustrated to install openCV using other sources. Then this tutorial just took me few minutes to successfully install.

    Reply
  8. haroun says

    November 20, 2017 at 8:03 am

    hello
    thank you for this tutorial it was very helpful for me
    to use this installation with Spyder
    from the anaconda navigator go to the icon “Applications on” and change it from “root” to the environment you have created
    launch Spyder from there and it will works.

    Reply
    • shruti says

      December 4, 2017 at 8:22 am

      thank you

      Reply
  9. Nayyer says

    January 20, 2018 at 11:10 pm

    Many thanks! really cool way!!

    Reply
  10. Shaury Baranwal says

    February 6, 2018 at 8:07 am

    I have downloaded Opencv in Windows 8 by following the steps. But when I import cv2, a popup appears saying Python has stopped working. Please suggest what I am doing wrong.

    Reply
  11. M says

    February 13, 2018 at 5:50 am

    Thank you so much Chris for this tutorial! I’ve spent 2 days to come up with a way to install openCV with python 3.6 and tried dozens of tutorials but to no avail. Yours worked like a charm with 3.5 version!

    Reply
    • Chris Conlan says

      February 20, 2018 at 1:40 am

      Hey glad I could help!

      Reply
  12. Nahid says

    February 18, 2018 at 8:22 pm

    hey!
    I followed the steps
    and it’s successfully done
    but still I m not able to import cv2

    Reply
    • Chris Conlan says

      February 20, 2018 at 1:41 am

      Hi Nahid,
      Try reading some of the comments and see if you find a similar situation to your own. Some people have found crafty ways to run cv2 from different IDE’s.
      Best,
      Chris

      Reply
  13. guy says

    March 29, 2018 at 5:06 pm

    Hi, thanks for the tutorial. I really struggling to get open cv work. I have followed the instructions but when running:
    conda install –channel https://conda.anaconda.org/menpo opencv3
    I getting the following.
    Unsatisfiable error: the following specifications were found to be in conflict:
    -opencv3
    -Zict
    Use “conda info ” to see the dependancies for each pakage.
    any help

    Reply
    • Chris Conlan says

      April 2, 2018 at 8:19 pm

      Hi there,
      I am not sure what “Zict” is, but I recommend you uninstall it and try to install OpenCV in a separate Anaconda environment.
      Best,
      Chris

      Reply
    • utk says

      May 17, 2018 at 10:46 am

      I was getting the same issue friend, then what i did was just opened that myWindowsCV environment rather then using base anaconda environment (as written above in the blog) then it worked fine.

      Reply
  14. Rishabh Gupta says

    April 15, 2018 at 4:04 am

    Thanks a lot Sir

    Reply
  15. usman says

    April 22, 2018 at 3:03 pm

    hi.i have installed the anaconda and python and successfully import opencv2.But i want to run jupyter notebook and want to import opencv 2 in jupyter notebook.please guide me.thanks

    Reply
  16. Debdatta Chatterjee says

    June 6, 2018 at 6:09 am

    Sir,
    After following all the steps I am facing this problem
    Traceback (most recent call last):

    File “”, line 1, in
    import cv2

    ImportError: DLL load failed: %1 is not a valid Win32 application.

    in my spyder environment.
    Please help.

    Reply
  17. Aswini says

    July 10, 2018 at 9:13 am

    sir,
    I am new to python. Translating slowly from matlab. I am not able to call sift( ) function when i try to run few programs coming in opencv python tutorials.

    http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_table_of_contents_feature2d/py_table_of_contents_feature2d.html

    Please suggest how to proceed. I have anaconda 3. Which version of python and opencv i should use? In one site, they specify to install opencv_contrib. I dont exactly get how to do.

    Reply
    • Jay Frankie says

      July 15, 2018 at 11:21 pm

      Thanks Chris..this turned into a weekend project until i found your post and all worked as stated in your steps on a Windows 7 box..thanks!!!

      Reply
  18. Saad says

    August 1, 2018 at 6:29 pm

    will opencv run in anaconda enviroment only or it can be used by any application on windows?

    Reply
  19. Garima says

    August 23, 2018 at 3:44 pm

    Even after following all the steps as given above, I am getting the following error:

    ImportError: DLL load failed: %1 is not a valid Win32 application.

    I am using windows 8.

    Reply
  20. a naveen says

    August 31, 2018 at 1:32 am

    i have installed opencv in anaconda promp and it is successfull
    but it is showing error in jupyter notebook can u help me in solving that

    Reply
  21. Lawrence Nwaogo says

    September 14, 2018 at 5:42 pm

    I was able to install opencv without problem, thanks a lot.

    Reply
  22. gigi says

    May 22, 2019 at 4:52 am

    dear all.. I success to Install with this tutorial
    but i had a problem
    when i install opencv3 with that instruction, my Python was downgrade to 2.7 version
    so.. that is normal ?

    how to got the opencv with the latest python ?
    thanks a lot for ur attention

    Reply
  23. Mafaz Ahsan says

    September 8, 2019 at 10:09 pm

    After following all the steps, I am getting error UnavailableInvalid channel “The channel is not accessible or is invalid”.

    Reply
  24. oladehinde says

    April 22, 2020 at 9:12 pm

    Hello. I installed opencv3 successfully but I can’t import other libraries like pandas and matplotlib. How do I solve this please?

    Reply

Leave a Reply Cancel reply

Fast Python: Master the Basics to Write Faster Code

Fast Python: Master the Basics to Write Faster Code

Available for purchase at Amazon.com.

Featured Posts: Python Programming

Pulling All Sorts of Financial Data in Python [Updated for 2021]

When to Use Heap Sort to Speed Up your Python Code

Fastest Way to Flatten a List in Python

Topics

  • 3D Technology and Virtual Reality (8)
  • Automated Trading (9)
  • Business Management (9)
  • Chris Conlan Blog (5)
  • Computer Vision (2)
  • Programming with Python (16)
  • Programming with R (6)
  • Snippets (8)
  • Email
  • LinkedIn
  • RSS
  • YouTube

Copyright © 2021 · Enterprise Pro Theme On Log in