This is an old blog and some information might be obsolete. We have published new instructions. You can find them here:
We already have a post for installing OpenCV 3 on Windows which covers how to install OpenCV3 from source for working with both C++ and Python codes. However, many readers have faced problems while installing OpenCV 3 on Windows from source. This post is for those readers who want to install OpenCV on Windows for writing Python code only.
If you are still not able to install OpenCV on your system, but want to get started with it, we suggest using our docker images with pre-installed OpenCV, Dlib, miniconda and jupyter notebooks along with other dependencies as described in this post.
Step 1: Install Anaconda (a python distribution)
Download and install Anaconda 64-bit version from https://www.continuum.io/downloads.
It is advised to install Anaconda for Python 3.
While installing Anaconda make sure that you check both options:
- Add Anaconda to my PATH environment variable
- Register Anaconda as my default Python
Step 2 : Create Virtual Environment
Open the command prompt and execute the following command.
conda create --name opencv-env python=3.6
You should get an output as shown below:
Press Enter and the environment will be installed and you should get an output as shown below :
Step 3 : Install OpenCV
3.1. Activate the environment
# See how the (opencv-env) appears before the prompt after this command.
activate opencv-env
3.2. Install OpenCV and other important packages
Continuing from the above prompt, execute the following commands
pip install numpy scipy matplotlib scikit-learn jupyter
pip install opencv-contrib-python
pip install dlib
3.3. Test your installation
Open the python prompt on the command line by typing python on the command prompt
import cv2
cv2.__version__
import dlib
dlib.__version__
You should get the following output
“It is advised to install Anaconda 3.” Did you mean Python 3 or Anaconda 3? (In the picture i see Ananconda version 4.3.1). Thank you for your great post 😀
error to install dlib saying that CMake must be istalled runtime error
same here
have you found the solution?
Install cmake:
pip install CMake
from where to install
I installed CMAKE still getting error. I am using pycharm and not anaconda. Getting error – “CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage”
Same here too
You need Visual Studio 2017
Same here too.. :'(
pip install cmake
Why not “conda install dlib opencv -c conda-forge”?
that made my opencv installation fail too
Can anyone help?? When I try to setup virtual enviornment using the following command
conda create –name opencv-env python=3.6
I get the following error
‘conda’ is not recognized as an internal or external command, operable program or batch file
What could be the issue ??? Thank you in advance
When I follow this procedure I still get the error: AttributeError: module ‘cv2’ has no attribute ‘SIFT’.
I thought SIFT and SURF were included in the conrib package?
Any hints and tips on how to add SIFT and SURF?
Here you go 😀
https://www.pyimagesearch.com/2015/07/16/where-did-sift-and-surf-go-in-opencv-3/
conda install opencv
Installs version 3.3.x
I´m install opencv_python-3.4.0, but whe I activen open -env, i receive the message:() 1>&2 Error: did not expect more than one argument. someone can help me?
Hi,
I can’t install dlib as I got this error msg : ” Failed building wheel for dlib”. Any idea on what to do next ?
Thanks !
The easy way: Just download the Python Wheel file from this page (https://pypi.python.org/pypi/dlib/18.17.100) and just type “pip install Dlib-Python-Wheel-file-Name.whl”
that page gets 404 error, is there another link that you could provide?
Hi, go to https://pypi.org/simple/dlib/ and download the most recent version that is compatible with your system
Thanks a lot. I have been struggling for so many days. This really helped.
i really help me.. i have been struggling for so many days.
Try dumping installation output to log file like so …
>pip install dlib > c:tempdlib_install.log
I had same problem. In my case dlib could not install without cmake working while cmake could not work without c++ runtime installed. So I ended up going back to adding C++ to Visual Studio like it says in Step 1 on https://learnopencv.com/install-opencv3-on-windows/. After that dlib installed.
opencv_python-3.3.1+contrib-cp36-cp36m-win_amd64.whl
it not available at given link https://uploads.disquscdn.com/images/53c46b8c7aa70b199099650f44a57733a147c164bf662f3096676f0ac05f8a6d.png
pip install dlib
it displaying error.. plz anyone help me https://uploads.disquscdn.com/images/c07c59da89abcdb7562dfba09e05fb3ef3faae261c11db2b203b68b10b5fce2c.png
The easy way: Just download the Python Wheel file from this page (https://pypi.python.org/pyp… and just type “pip install Dlib-Python-Wheel-file-Name.whl”
http://www.codesofinterest.com/2016/10/installing-dlib-on-anaconda-python-on.html for dlib errors
Thanks Piyush , it worked for me.
conda install -c conda-forge dlib=19.4
it didn’t return any errors, but when I import dlib it says that there is no module named dlib
https://uploads.disquscdn.com/images/8d989f23f489675a2922dfcc1586c161e5204e70f6d63e30a66a555decd5ab9e.png it displaying error can any one help me .. thanks in advance
Hello everyone , i have an error on the installation of open cv and numpy
please some one can help fix this problem ?
i found the way to fix it, you should run your cmd as an administrator , for those who have the same problem, makke sure to upgrade your pip version by typing ; python -m pip install –upgrade pip
I have a problem on step 3.3, there was an error saying
AttributeError: module ‘cv2.cv2’ has no attribute ‘_version_’
how can i solve this?
thanks in advance
Did you find a solution?
it’s two underscores each: _ _ version _ _ (without whitespaces).
Best way to install python with opencv is using pycharm. That i have shown bellow.
1.download and install pycharm community addition.
2.create new project in pycharm.
3.go to its settings from file menu or press…ctrl+alt+s
4.search for interpreter in searchbar.find the green coloured ‘+’ button from right side to add new interpreters.
5.find the opencv, matplotlib, numpy then search and install them. You dont have to type any command for these stuf here, its GUI(it will add these libraries to your project folder and you are ready to rumble)…☺️☺️
right everything installs except dlib.
Best way to install python with opencv is using pycharm. That i have shown bellow.
1.download and install pycharm community addition.
2.create new project in pycharm.
3.go to its settings from file menu or press…ctrl+alt+s
4.search for interpreter in searchbar.find the green coloured ‘+’ button from right side to add new interpreters.
5.find the opencv, matplotlib, numpy then search and install them. You dont have to type any command for these stuf here, its GUI(it will add these libraries to your project folder and you are ready to rumble)…☺️☺️
I dont understand…why here these guys trying to install dilib…?
Wow, I spent SO much time trying to get dlib to work. Your tutorial did it for me. After so much frustration, I couldn’t believe that it finally worked. Thank you so much for this nice and easily understandable explanation!
Hi,
How to install dlib use GPU on windows?
dlib installation pretty much fails for windows. Is Mac the only other option ? I tried all the ways. visual studio 2015 installation, cmake, “https://learnopencv.com/install-opencv3-on-windows/”
nothing works.
CMake Error in CMakeLists.txt:
No CMAKE_C_COMPILER could be found.
CMake Error in CMakeLists.txt:
No CMAKE_CXX_COMPILER could be found.
— Configuring incomplete, errors occurred!
did you fix it? I got the same problem :((
for dlib installation which is the last and most painful installation. i found out from other post. this works.
conda install -c menpo dlib
Thanku so much your method for dlib installation worked in my window7 os.
yes it works here try installing on pycharm the same dlib fails. eventually i cant install facialrecognition which is what i want to do. Windows i heard is not only painful for CV its impossible
I got an error, what should I do? Do some one know? Please help me!!!
— RuntimeError:
*******************************************************************
CMake must be installed to build the following extensions: dlib————————————–
Command “C:UsersTRANTHIHAIUYENAppDataLocalContinuumanaconda3envsopencv-envpython.exe -u -c “import setuptools, tokenize;__file__=’C:\Users\TRANTH~1\AppData\Local\Temp\pip-install-14vqi61x\dlib\setup.py’;f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace(‘rn’, ‘n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record C:UsersTRANTH~1AppDataLocalTemppip-record-xipyuon9install-record.txt –single-version-externally-managed –compile” failed with error code 1 in C:UsersTRANTH~1AppDataLocalTemppip-install-14vqi61xdlib
hello.
I just installed cmake and setuptools in the conda env with:
conda install setuptools
conda install cmake
and after that the dlib started to build.
Hi,
I am using pycharm. What are the steps of installation on pycharm?
At the last check im having this issue diferent form the example any clue?
(opencv-env) C:UsersUSUARIO>python
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:27:44) [MSC v.1900 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import cv2
>>> cv2.__version__
‘3.4.2’
>>> import dlib
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘dlib’
>>> dlib.__version__
Hi,
i can’t install dlib, i got this error: https://uploads.disquscdn.com/images/7d3fe61bac926c12e49b9696b8665e1d8c1ac66e19ed6a821ba619564ff2ba50.png
can u help me fix it? thank a lot!
You can check my comment and try that but right now there seems to be another (kinda) problem. You seem to be working on Py2.7
thanks
hi,
use the following command in anaconda prompt
conda install -c anaconda cmake
and then
pip install dlib
thanks u very much!
For those struggling with dlib on Windows, can copy and run following 3 commands (Screenshot attached on Win10):
pip install cmake
pip install setuptools
pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f
Screenshot:
https://uploads.disquscdn.com/images/64ecbacdc1db639da07f907aa4288299419abd6437cbeffd198eb09b20c36784.png
I have created the environment and then install it and then deactivated it.but when I try to use it in jupyter it’s showing no module named as cv2