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.
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
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
this was successfully installed
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.
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.
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?
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
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!
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!
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
Is it still applicable in the latest version of anaconda?
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.
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
***See comment thread, 3.5 is required***
Hi Mark, see the updated article. Python 3.5 is required for OpenCV 3 on Anaconda.
I was installing today and received the same error using 3.6. However, downgrading to 3.5 permitted the installation to complete.
I got the same error
I was installing today and I had the same error. Python 3.5 is still required for Anaconda.
in environment i try this (myWindowsCV) :\Users\bobby> conda install -c anaconda spyder
i got no error. My OS is windows 7
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.
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
>>>
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
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.
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.
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
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
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.
Thanks, I was totally frustrated to install openCV using other sources. Then this tutorial just took me few minutes to successfully install.
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.
thank you
Many thanks! really cool way!!
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.
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!
Hey glad I could help!
hey!
I followed the steps
and it’s successfully done
but still I m not able to import cv2
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
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
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
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.
Thanks a lot Sir
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
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.
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.
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!!!
will opencv run in anaconda enviroment only or it can be used by any application on windows?
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.
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
I was able to install opencv without problem, thanks a lot.
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
After following all the steps, I am getting error UnavailableInvalid channel “The channel is not accessible or is invalid”.
Hello. I installed opencv3 successfully but I can’t import other libraries like pandas and matplotlib. How do I solve this please?