How to use OpenCV in Python with VS as IDE - python

I have problems getting a project started. I want to work with the library OpenCV in Python, using Visual Studio 2017 as IDE (on windows 10). I added Python extensions (e.g. Anaconda3 64 Bit) to VS via the VS Installer. After that, the struggle begins. Someone told me, Anaconda would be nice to handle multiple packages, so I opened the Python IDE window and set Anaconda as default. Then in the same window I clicked on packages. After executing
conda install -c conda-forge opencv
conda install -c conda-forge/label/gcc7 opencv
conda install -c conda-forge/label/broken opencv
with the text field above the listed packages I was able to see the opencv package in that list. But when I tried to import opencv in a new python file, it didn't work. (The package was not found)
I also tried to download the latest OpenCV version on the official site, but there I got a folder. I navigated throught this folder and found some .pyd (python extension) files. Can I include them in VS?
I hope anyone can help, thanks in advance!

You can use/try/check the Python Environment Tab (View, Other Windows, Python Environment) to install stuff to any "environment" you have installed:
No idea if it is more comfy or not - I generally use that to install missing dependencies (using pypi - not conda) and the search input to check if it went ok:
I mostly use the python 3.6 for dev - so not much installed over anaconda defaults.
HTH

Related

"DLL load failed" when import cv2 (opencv)

In [windows server 2012 R2 x64, python 3.7 64x]
pip install opencv-contrib-python
installed without any error .
and when I try to import it
import cv2
show me this error :
Traceback (most recent call last):
File "test.py", line 1, in <module>
import cv2
File "C:\Program Files\Python37\lib\site-packages\cv2\__init__.py", line 3, in
<module>
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
and I see another topic about this error but their solution does not work for me :
- DLL load failed error when importing cv2
- Failure to import cv2 in python : DLL load failed
- and a lot of pages in here
some of them say about that problem because anaconda, and I don't have anaconda even. and many say that problem 32 or 64 version, I try both and disappointment. many about system variables...
what dll failed to load? cv2? why?
what i try till now:
change python version : 3.5, 3.7, 2.7 in 86x and 64x (uninstall complete last version and delete all remain files in program files ... then install new one)
try with another packages like : opencv-python, opencv-contrib, try install specific versions with .whl (in some topic i read about this so install numpy-1.14.5+mkl-cp37-cp37m-win_amd64.whl and opencv_python-3.4.3+contrib-cp37-cp37m-win_amd64.whl but anything not change)
import numpy before cv2 for every test
installed Microsoft Visual C++ 2015 Redistributable Update 3 , 2008 , 2010 , 2017 for 64x
UPDATE
NEXT 2 DAY
I try to manage missing dll base on dependency walker that mention in bellow post, download all dll and put them in system 32, its a good clue but not solve the problem.
DAY 4,5
my next step , trying compile OpenCV in my machine , install visual studio 2012 + cmake and base on document compile 2 version , 64x and 32 , compiling have a lot of problem itself (like missing some lib from c lang and need to install Visual C++ Redistributable for Visual Studio 2012 ...) and I resolve all of them ,then I have 2 success compiled version but both have the same problem with missing dll, the compile process is so slow and give 2 day from me. so if fail on this mission :/ I search for a new way...
DAY 6
my next step is to try to run OpenCV in my machine with docker ( I try but docker windows just install on windows 10 and windows server 2016) so I search for an alternative. I found Vagrant that work like docker but with VM (visual box) today my time spend for this articles, it's amazing, the concept of docker and vagrant is so Attractive, and I play with this like that I have new puzzle :)
first error show on ... and limitless errors go on :
Day 7
Vagrant tests failed too because my windows server 2012 is a vb machine (visual server) and run a visual box in another visual box impossible!
so I need new clues :
Day 8-9
try install vagrant with VMware , I download VMware, unfortunately this plugin is not free (79$) so I try to work with pythonanywhere.com that 'gives you access to machines with a full Python environment already installed.' in this free account, you can't openurl with urllib , and more limit...
so I wanna try to install ubuntu in VMware my self... I read here results after work. it's Impossible with same reason vb (visual box)
This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.
Update May 2020: There is a new way to install media pack for Windows 10 N.
https://support.microsoft.com/en-us/help/4562569/media-feature-pack-for-windows-10-n-may-2020
I had the same error (although I compiled OpenCV myself), in my case there were some DLL dependencies missing. You can check that with the program Dependency Walker.
Download Dependency Walker and run it, and open the file cv2.pyd with Dependency Walker, it should be in C:\Program Files\Python37\lib\site-packages\cv2\ if the pip package installed correctly.
This program then scans for dependencies (which may take a few minutes) and it then shows missing DLL files in red.
I have faced the similar issue in Windows Server 2012 r2. After lot of findings I found that mfplat.dll was missing which is related to Window Media Service.
Hence you have to manually install the features so that you can get dll related to window media service.
Turn windows features on or off
Skip the roles screen and directly go to Feature screen
Select "Desktop Experience" under "User Interfaces and Infrastructure"
After this all required dll of opencv would be available.
Python 3.7 may not support some modules.
Try installing python 3.6.4
Using command prompt, "pip install
opencv" or "pip install opencv-python"
Import cv2
Can you try uninstalling opencv and installing it using a wheel file instead? Here is a website that has many versions of OpenCV compiled for windows, search for the one you need and simply install it with pip command.
So if you have Python 3.6 (64 Bit) and wish to install OpenCV 3.4.3 then download the wheel file:
opencv_python‑3.4.3‑cp36‑cp36m‑win_amd64.whl
I had similar issue except that I'm using Anaconda3 and this code here solved it:
conda install -c anaconda py-OpenCV
After 15 days of brain storming, This solution worked for me. And I am sure that it will work for you too. I installed anaconda to use OpenCV 3.1.0. I followed following Steps:
1) I have installed anaconda-5.3 64-bit installer (614.3 MB) which uses python 3.7. You can download anaconda from link: https://www.anaconda.com/download/#windows
2) After installation of anaconda, open anaconda prompt by typing "anaconda prompt" on windows start button. Open with "Run as administrator".
3) You have to create new environment to install and use OpenCV module.Write following commands to create and activate new environment:
>conda create --name myNewEnv python=3.5.0
>activate myNewEnv
"myNewEnv" is the name of new enviroment.
4)Now you need to install prerequisite for OpenCV, which is numpy and then install opencv3. Start internet before executing following commands:
>conda install numpy
>conda install anaconda-client
>conda install --channel https://conda.anaconda.org/menpo opencv3
5)OpenCV3 has been installed. Now, verify installation by executing following commands:(myNewEnv) C:\Users\Nilesh> python
>>>import cv2
>>>cv2.__version__
Follow steps given below, when you want to start OpenCV3 second time onwards:
1) Open "anaconda command promt" from start menu with "run as administrator" rights
2) Type command >activate your_new_environment_name
3) Assume that you want to run file located on desktop, for that write following command:
> cd C:\Users\Nilesh\Desktop
4) Now your working directory is Desktop.
5) Type following command to run any code (for example test.py).
> python test.py
Note: Here, python means version-3.
I hope this solution will work for you.
I had the same problem on Windows Server 2012 R2 x64. I was creating executable file using PyInstaller and got error in runtime:
ImportError: DLL load failed: The specified module could not be found.
After installing "Visual C++ redistributable" 2015 and enabling "Media Foundation" feature my problem was resolved.
There is more informations in documentation: OpenCV Documentation
I was having this problem on Windows. I resolved this error by checking instructions here.
Q: Import fails on Windows: ImportError: DLL load failed: The specified module could not be found?
A: If the import fails on Windows, make sure you have
Visual C++ redistributable 2015 installed.
If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.
Windows N and KN editions do not include Media Feature Pack which is required by OpenCV. If you are using Windows N or KN edition, please install also Windows Media Feature Pack
i was suffering from the same problem "DLL load failed" after reading tons of answers and articles i got a solution.
i don't know this works for you or not but give it a try.
tools and versions i used: anaconda - 5.3.1, python - 3.7, win 10 (64 bit)
Steps i performed :
step1:i installed opencv 3.4.4 from here
then extract into C drive (you can do wherever you want)
step2: copy cv2.pyd file from [C:\opencv\build\python\cv2\python-3.7] here to [C:\Users\"user-name"\Anaconda3\Lib\site-packages] here.
step3: run dependency walker to detect which dll files are missing,
after running dependency walker in my case it showed two dll files are not loading, they are (1)OPENCV_WORLD344.DLL and (2)IESHIMS.DLL.
i don't know about your situation but you can do this-> find files name using dependency walker then find their path and follow step4.
step4: open System property->Advanced->Environment variables, now edit path and add C:\opencv\build\x64\vc14\bin (in my case this was the place where OPENCV_WORLD344.DLL is stored) and after doing this, import cv2 in python.
If my answer does not work then add a comment.
It helps me pip install opencv-contrib-python Anaconda Prompt, python 3.7.1 cv2 4.1.1
I was having the same issue. I resolved this error by downgrading open cv.
pip install opencv-python==3.3.0.9
its worked well for me.*
Answer is Need to put cv2.pyd file to your virtual environment.
need to put under two folder of envs,
first is under DLLS folder and
Second is under Lib/site-packages
To get cv2.pyd > download from this link https://sourceforge.net/projects/opencvlibrary/ and then extract the download file
You will get opencv folder, after that go inside opencv folder like Downloads\opencv\build\python\2.7 and go one deeper folder depend on your 32 or 64 window version
Copy cv2.pyd Important **** after copying cv2.pyd file to your envs, you need to rename cv2.pyd to _cv2.pyd
I was having this problem on Windows Server 2008R2 fresh install and took almost a day to resolve, as was trying with many hits and trials finally I found solution somewhere in internet (not stackoverflow)
Installed Windows Media Feature Pack for 2008R2 then installed Server Manager-> Features-> Add Features-> Desktop Experience
Server Manager-> Features-> Add Features-> Desktop Experience
and Ink and Handwriting Services.
Besides check list includes
Visual C++ redistributable 2015
Universal C Runtime
Hopefully its will help save time
Installing Python version 3.6 and then installing opencv with the command:
pip install opencv-python==3.3.0.9 resolved this issue for me
All you need is python 3.6.
I've been looking for solution for last 3 days and my problem was solved when i installed python 3.6.7.
After installing python 3.6 you can simply run pip install opencv-python.
Source: https://www.geeksforgeeks.org/setup-opencv-with-pycharm-environment/
Just ran into this problem of cv2 importable from my conda environment but not through the "same" environment in jupyter. The error I was getting was that it couldn't load the dll.
Additionally, I could not get opencv installed through jupyter, even using:
import sys
!conda install --yes --prefix {sys.prefix} numpy
I checked my path using:
import os
os.path
in both my shell and jupyter. They were the same(!).
I was finally able to get things working by running the command:
conda install nb_conda
in my conda environment, as outlined here: https://github.com/udacity/P1_Facial_Keypoints/issues/13
This was eye opening as it created a new install of jupyter note books associated with my env instead of anaconda, with five(!) environments to choose from when creating a page. There were three that seemed to be associated with my conda environment. Interestingly, now it only shows the one named environment as an option when creatin a new notebook again in jupyter (the one associated with the env), but it successfully imports cv2.
For a good read on why this is happening with jupyter:
https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/
Came here from Windows 10N, upgraded to Windows 11. Had to install Media Feature Pack under Settings -> Apps -> Optional Features -> Add an optional feature.
Windows settings

OpenCV - Can't import cv2 [duplicate]

How to install opencv with python 3.6 and anaconda 3.6?
I tried conda install -c https://conda.binstar.org/menpo opencv3
but i get the following error:
UnsatisfiableError: The following specifications were found to be in conflict:
- opencv3 -> python 2.7*
- python 3.6*
Use "conda info <package>" to see the dependencies for each package.
I am using Windows 10 64-bit, with python 3.6, and anaconda 3.6 installed.
Is it even available for python3.6 at the moment or should i rollback my python version to 3.5.*?
search anaconda prompt
open and run the command.
> pip install opencv-python
this single command help's you to install opencv easily.
you can take help from the video link below.
video link
From menpo file page, it shows that the OpenCV 3.2 binary there are only for Python 2.7/3.4/3.5 and on linux-64 platform
You may go to the this site to get the exact version you need.
opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl is the basic one.
opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl is the one
with opencv-contrib modules such as the text module for binding to tesseract OCR engine and many others.
Both binary are for OpenCV 3.2 with Python 3.6 binding for Windows 64-bit. To install it, 1) download the binary to local drive, 2) open your Anaconda command prompt and 3) type the command below in the directory the binary locates.
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
Hope this help.
Update on 2018-02-22:
OpenCV 3.4.0 wheel files are now available in the unofficial site and replaced OpenCV 3.3.0
Update on 2019-01-30:
OpenCV 4.0.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
I managed to get it working by doing the following:
Download and install python3.6 from official python site
https://www.python.org/downloads/release/python-360/
Download and install Anaconda 4.4.0 from the official anaconda site
https://www.continuum.io/downloads
Open command line and run:
pip install opencv-python
Open command line and run:
pip install opencv-contrib-python
I am using Windows 10 and it worked for me.
It's pretty simple..
Install Anaconda 3.6. Check anaconda is added to System Variable Path.
Open CMD and type conda install -c conda-forge opencv.
This will install latest OpenCV version available (3.6).
Open IDE editor and try import cv2.
It will probably don't work...don't worry.
You have to add cv2 command to editor.
For Eclipse (with PyDev):
Create firs a project and then do the following:
For PyCharm:
cv2 module probably won't work. Go to the Anaconda folder/Lib/site-packages/cv2 and copy the file cv2.cp36-win_amd64.pyd to the site-packages folder. Rename it cv2.pyd
Now try to write a command... cv2.imread(). If auto-completition don't work, try cv2.cv2.imread().
This will work for sure.
I am using Python 3.6.2 and Anaconda 4.3.23 (It should also work with your case).
I did the following:
Download the Numpy version corresponding to your Python installation from here. In my case, I’ve used numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl
Download the OpenCV version corresponding to your Python installation from here. In my case, I’ve used opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
Now go to the folder where you downloaded these files and run the following:
pip install numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl
pip install opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
Note the Successfully installed … message after each command.
At this point, you should be able to play with OpenCV and Python. Let’s try a small test first. Start the Python interpreter or Jupyter Notebook and write:
import cv2
print(cv2.__version__)
If everything was correctly installed, you should see the version number of your OpenCV install, in my case this was 3.3.0.
I see you found a solution but this may be helpful for others. The package is not available for Python 3.6. You can check this by going to that package channel on anaconda.org and selecting the files tab. You will see the package tarballs with the Python version listed as py27, py34, py35,etc. This is a good way to check for Python versions of a specific package.
You can also run the following to see the package versions and Python versions available for your OS from the Anaconda channel:
conda search <package_name>
Or to search a particular channel and package you can do this:
conda search -c <channel_name> <package_name>
As of March 2018, OpenCV 3.4 can be installed directly from conda-forge or anaconda in Windows/OSX/Linux for Python 3.6
conda install -c conda-forge opencv
or
conda install -c anaconda opencv
Using:
conda install -c conda-forge opencv
worked for me
If you have installed anaconda then you should uninstall it, then try
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
It worked for me.
Thank You.
I am using python 3.6 and the following worked for me:
Download and install opencv (Win pack) on your computer from the official website:
https://opencv.org/releases.html (I took version 3.4.2)
Go to the website of Christoph Gohlke and download the wheel file corresponding to your system. (I took opencv_python-3.4.2-cp36-cp36m-win_amd64.whl)
As mentioned on the website of Christoph Gohlke, make sure you installed 'numpy1.14' & 'mkl' package. Also make sure you use pip with version 9 or newer.
Start the 'Anaconda Prompt'
Change the directory in the 'Anaconda Prompt' to the folder where you downloaded the wheel file from Gohlke's website (via the MS-DOS command 'cd').
In the 'Anaconda Prompt' type 'pip install opencv_python-3.4.2-cp36-cp36m-win_amd64.whl') (change the name of the wheel file accordingly).
When starting spyder, test your installation as follows:
import cv2
print(cv2.__version__)
If the version is printed in the console (in my case 3.4.2), your installation was successful.
IMPORTANT REMARK:
If you created a dedicated environment within Anaconda (in my case 'py36'), make sure you installed spyder for this dedicated environment ('conda install spyder'). If not, your installation of opencv will not be recognised within the environment you are working in. Maybe this is obvious and straightforward but in my case I struggled to find this solution.
First Download Anaconda Python 3.6 from official site. After installing anaconda, simply open command prompt and type following statement and press enter of course -
conda install -c conda-forge opencv
It may take some time. After the completion, check your conda packages by typing conda list - opencv should be there.
However, Before proceed to install opencv, you can check whether opencv for python 3.6 is available or not. We can check it by typing conda info opencv in command prompt and press enter of course, you'll see following -
opencv 3.3.1 py36h20b85fd_1
---------------------------
file name : opencv-3.3.1-py36h20b85fd_1.tar.bz2
name : opencv
version : 3.3.1
build string: py36h20b85fd_1
build number: 1
channel : https://repo.anaconda.com/pkgs/main/win-64
size : 96.7 MB
arch : None
constrains : ()
license : BSD 3-clause
license_family: BSD
md5 : e65c68524073445511ace8ade7ae3641
platform : None
subdir : win-64
timestamp : 1512689066576
url : https://repo.anaconda.com/pkgs/main/win-64/opencv-3.3.1-py36h20b85fd_1.tar.bz2
dependencies:
jpeg >=9b,<10a
libpng >=1.6.32,<1.7.0a0
libtiff >=4.0.9,<5.0a0
numpy >=1.11.3,<2.0a0
python >=3.6,<3.7.0a0
vc 14.*
zlib >=1.2.11,<1.3.0a0
By this we can also get ensure that opencv 3.3.1 py36h20b85fd_1 is available. And this is available for python 3.6
I think this way is straight forward. Just install anaconda from official page and follow the image.
Using Anaconda3's package manager directly will be more reliable and cross-platform:
conda install opencv

Python refactoring fails in Visual Studio Code

I switched to Visual Studio Code for Python programming recently. Below is my Python configuration in Visual Studio Code settings:
"python.pythonPath": "/Users/hzhang/.virtualenvs/env-2.7/bin/python",
"python.autoComplete.extraPaths": [
"/Users/hzhang/Work/xxx/shared_modules"
],
Basically, I just configure the Python interpreter and add one extra shared module path.
When I try to refactor a variable name, it throws this error which says rope is not installed, and it doesn't work even I install it. Based on my understanding, refactor variables is a feature of Visual Studio Code, and it shouldn't rely on any specific language.
How can I fix this problem?
Once I installed rope, refactor was still not working. It popups this error:
I am on Python 2.7
Visual Studio Code: Version 1.19.3 (1.19.3)
Rope version: 0.10.7
Renaming of variables is not a native Visual Studio Code feature for languages other than JavaScript and TypeScript.
It is specific to each language, and functionality is provided by separate extensions, specific to each language. The Python extension you have installed, uses the Rope library to perform refactoring/renaming of python variables and the like. So yes, you'll need to install it by closing in the Install rope button.
If you don't have the Install rope button, you can just go to cmd and type pip install rope. That should do the job as well.
If it doesn't work even after installing it, please could you file an issue on the Python extension GitHub repository.
Update from the filed bug: Anaconda users need to install the Anaconda package instead of the regular pip default install that Visual Studio Code provides.
This worked for me:
conda search rope # The latest right now is 0.11.0
conda install --name mypy27env rope
On Ubuntu, miniconda:
I had this issue using the "VSCode Python Plugin", when selecting "conda" install for rope.
I changed the active env with Terminal using "conda activate env". Then with "conda list", I saw Build Row was at value py_0 and at version 0.16.
I've chosen conda remove rope
Then, installing with pip (rope version 0.17.0): pip install rope
"conda list" gave me now pypi_0 as value in Build row
Restart VSCode
Summarize, one of this helped:
- Reinstalling rope with pip in the active conda environment
- Restarting VSCode

DLL load failed error when importing cv2

I have installed opencv on my windows machine using python 3.6 without any issues, using:
pip install opencv-python
but when I try to import cv2 I get the following error
ImportError: DLL load failed: The specified module could not be found.
I have seen this post
It says cv2 doesn't work with python 3 I was wondering if this has been fixed or if there is a way around it
I took a lot of time to solve this error!
Run command
pip install opencv-contrib-python
You can download the latest OpenCV 3.2.0 for Python 3.6 on Windows 32-bit or 64-bit machine, look for file starts withopencv_python‑3.2.0‑cp36‑cp36m, from this unofficial site. Then type below command to install it:
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win32.whl (32-bit version)
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl (64-bit version)
I think it would be easier.
Update on 2017-09-15:
OpenCV 3.3.0 wheel files are now available in the unofficial site and replaced OpenCV 3.2.0.
Update on 2018-02-15:
OpenCV 3.4.0 wheel files are now available in the unofficial site and replaced OpenCV 3.3.0.
Update on 2018-06-19:
OpenCV 3.4.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.0.
Update on 2018-10-03:
OpenCV 3.4.3 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.1.
Update on 2019-01-30:
OpenCV 4.0.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
Update on 2019-06-10:
OpenCV 3.4.6 and OpenCV 4.1.0 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
Update on 2023-02-11:
OpenCV 4.5.5 wheel files are now available in the unofficial site with CPython 3.7/3.8/3.9/3.10/3.11 support.
If you are using Anaconda with python 3.5, this is a problem in the Anaconda release. (Refer this issue)
You can fix this issue by copying python3.dll file to Anaconda3 folder (where python.exe is located)
How to get "python3.dll"
In cmd, type python --version to find whether your installation is 64-bit or 32-bit
download python 3.x embeddable zip file from here
Extract the zip file and copy python3.dll file to Anaconda3 folder
But if you can move to Anaconda with python 3.6 you will not face this issue. If it is possible for you, then it is the recommended way..
Recently I have faced the similar issue in Azure Windows Server 2012 r2 . Tried all option with and without Anaconda but none of them helped. After lot of findings I found that mfplat.dll was missing which is related to Window Media Service.
Hence you have to manually install the features so that you can get dll related to window media service.
1.Turn windows features on or off
2.Skip the roles screen and directly go to Feature screen
3.Select "Desktop Experience" under "User Interfaces and Infrastructure"
After this all required dll of media services for opencv would be available.
So if you are planning to run your code in cloud(Window Server) then please dont forget to select Desktop Experience feature.
I ran into this problem on Windows 10 (N) with a new Anaconda installation based on Python 3.7 (OpenCV version 4.0). None of the above advice helped (such as installing OpenCV from the unofficial site nor installing VC Redistributable).
I checked DLL dependencies of ...\AppData\Local\conda\conda\envs\foo\Lib\site-packages\cv2\cv2.cp37-win_amd64.pyd using dumpbin.exe according to this github issue. I noticed a library MF.dll, which I figured out belongs to Windows Media Foundation.
So I installed Media Feature Pack for N versions of Windows 10 and voilà, the issue was resolved!
After spending too much time on this issue and trying out all different answers, here is what found:
The accepted answer by #thewaywewere is no longer applicable. I think this was applicable when opencv-python module still wasn't available.
This is indeed a bug in Anaconda 4.2 because they forgot to ship python3.dll. They have fixed this in next releases but unfortunately 4.2 is the last release with Python 3.5 as default. If you are stuck with Python 3.5 (for example VS2015 is only aware of versions up to 3.5) then you must manually download python3.dll as described in answer by #Ramesh-X.
If you can move on to Python 3.6 (which at present bit difficult if you are using OpenCV and VS2015) then just install latest Anaconda version and you don't have to deal with any of these.
There are many questions on that and many suggestions. None of them helped me for the recent Opencv 3.4.16 and Python 3.6/3.7.
Finally I switched to Pyhon 2.7.15 and installed opencv 3.1.0. The DLL-problem was solved.
When I look in cv2.pyd with dependency walker, the 3.1 has no dependency to one missing dll. Opencv 3.4 has this missing dependency to this dll:
API-MS-WIN-DOWNLEVEL-SHLWAPI-L1-1-0.DLL
may be this is the problem.
P.S.: I have Win7 pofessional 64Bit, 32Bit Python 2.7.15
Frankly there are a lot of very smart and complicated answers here. Mine is dumb and simple. I deleted my conda environment, re-installed from scratch, taking pains to install opencv first. This fixed my problems. Environments are meant to be temporary and diaphanous -- don't get too attached.
So if my environment was called fubar first make sure every instance is deactivated (including any IDEs that are using it). Then remove it:
conda remove --name fubar --all
Now I simply recreate my environment and add opencv first:
conda create --name fubar
conda activate fubar
conda install opencv
And then go from there. First open python and make sure import cv2 works. Then you should be on your way. Note I always (always) install Spyder last as it tends to screw things up when I don't.
Note, if that doesn't work, we have had some cases where people have to uninstall and reinstall Anaconda, and then things worked. Obviously a last resort.
In my case a major update of Windows 10 removed some Windows packages, so other methods (reinstalling opencv etc.) did not help. To fix it, install:
a) Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
b) Media Feature Pack for N versions - needed only if you have Windows 10 N
Both need restart of PC.
I had the same issue when installing opencv 2.4.13 on Anaconda3 (Python 3.6)... I managed to fix this issue by reverting to Anaconda2 (Python 2.7)
this happens because the compiler or the interpreter is finding more than one package of the file, delete all the number of same package you have and then keep only one and then try to install. It serves
The issue is due to the missing python3.dll file in Anaconda3.
To fix the issue, you should simply copy the python3.dll to C:\Program Files\Anaconda3 (or wherever your Anaconda3 is installed).
You can get the python3.dll by downloading the binaries provided at the bottom of the Python's Release page and extracting the python3.dll from the ZIP file.
I had the same issue with python 3.6(Anaconda3) and OpenCV 3.4.1 for spyder to work. Even after copying cv2.pyd into Anaconda3 Users/home/Anaconda3/Lib/site-packages, it didn't work.
But found a solution
Later I installed OpenCV and Dlib on Anaconda and copied the generated cv2.cp36-win_amd64.pyd and dlib.cp36-win_amd64.pyd into Anaconda3 Users/home/Anaconda3/Lib/site-packages. These can be copied from environment folder C:\Users\home\Anaconda3\envs\opencv\Lib\site-packages.
Finally spyder started to work
I managed to get it to work by installing python 3.9.12 in a new environment (using conda), and then installing opencv in that environment. Because of my python version, opencv version 4.5.5 was installed instead of version 4.60.
(I had already updated VC2015-2022 and added the python3.dll to PATH; neither of these worked.)
I have the same problem. when I install WinPython programming, and run opencv after copy the cv2.pyd file from my opencv directory, it will be like this: C:\Users.....\Downloads\opencv\build\python\2.7\x64, x64 or x86 is depend on your 32 or 64 bit devices. and paste to C:\Users.....\Downloads\WinPython-64bit-3.5.4.1Qt5\python-3.5.4.amd64\Lib\site-packages, I prefer the previous python 3.5 than 3.6. Because when I "import cv2" installed (python 3.6) it shows directly: "ImportError: DLL load failed: The specified module could not be found"
Then I install python 3.5 and open WinPyhton Command prompt and type "pip install opencv-python".
The command prompt download opencv automatically, it shows the process like this "Successfully installed opencv-python-3.3.0.10"
Finally, I try to run open cv by type "import cv2", it works
i try to type "cv2.version", and shows: '3.3.0'
Under Winpython : the Winpython-64bit-.../python_.../DLLs directory the file cv2.pyd should be renamed to _cv2.pyd
(base) C:\WINDOWS\system32>conda install C:\Users\Todd\Downloads\opencv3-3.1.0-py35_0.tar.bz2
I ran this command from anaconda terminal after I downloaded the version from
https://anaconda.org/menpo/opencv3/files
This is the only way I could get cv2 to work and I tried everything for two days.
If this helps someone, on official python 3.6 windows docker image, to make this thing work I had to copy following libraries from my desktop:
C:\windows\system32
aepic.dll
avicap32.dll
avifil32.dll
avrt.dll
Chakra.dll
CompPkgSup.dll
CoreUIComponents.dll
cryptngc.dll
dcomp.dll
devmgr.dll
dmenterprisediagnostics.dll
dsreg.dll
edgeIso.dll
edpauditapi.dll
edputil.dll
efsadu.dll
efswrt.dll
ELSCore.dll
evr.dll
ieframe.dll
ksuser.dll
mf.dll
mfasfsrcsnk.dll
mfcore.dll
mfnetcore.dll
mfnetsrc.dll
mfplat.dll
mfreadwrite.dll
mftranscode.dll
msacm32.dll
msacm32.drv
msvfw32.dll
ngcrecovery.dll
oledlg.dll
policymanager.dll
RTWorkQ.dll
shdocvw.dll
webauthn.dll
WpAXHolder.dll
wuceffects.dll
C:\windows\SysWOW64
aepic.dll
avicap32.dll
avifil32.dll
avrt.dll
Chakra.dll
CompPkgSup.dll
CoreUIComponents.dll
cryptngc.dll
dcomp.dll
devmgr.dll
dsreg.dll
edgeIso.dll
edpauditapi.dll
edputil.dll
efsadu.dll
efswrt.dll
ELSCore.dll
evr.dll
ieframe.dll
ksuser.dll
mfasfsrcsnk.dll
mfcore.dll
mfnetcore.dll
mfnetsrc.dll
mfplat.dll
mfreadwrite.dll
mftranscode.dll
msacm32.dll
msvfw32.dll
oledlg.dll
policymanager.dll
RTWorkQ.dll
shdocvw.dll
webauthn.dll
wuceffects.dll`
Please Remember if you want to install python package/libraries for windows,
you should always consider Python unofficial Binaries
Step 1:
Search for your package, download dependent version 2.7 or 3.6 you can find it under Downloads/your_package_version.whl its called python wheel
Step 2:
Now install using pip,
pip install ~/Downloads/your_packae_ver.whl
this will install without any error.
I had the same problem and spent 3 full days wrestling with it. I tried everything suggested: upgrading pip, updating Visual C++, updating Anaconda, manually downloading files and basically every solution I could find on the web. Here's what finally worked maybe it'll help someone else:
1- I ditched Python 3 and Anaconda-based downloads since I noticed they had several problems and downloaded Python 2.7.16 64-bits instead.
2- Navigated to where Pip was located on my drive (for me the path is C:\Python27\Scripts) highlighted the path by selecting it, and typed "cmd" then enter so the Command Prompt opens on that path (I noticed skipping this usually brings about a couple errors)
3- Updated Pip using python -m pip install --upgrade pip on the CMD (again, skipping this and not updating it didn't let this procedure go through)
4- Downloaded the appropriate Wheel file from https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv (after trying several the one that worked for me was opencv_python-2.4.13.7-cp27-cp27m-win_amd64.whl) I copy-pasted it to the same folder Pip was in (C:\Python27\Scripts for me) and then installed it through CMD using: pip install opencv_python-2.4.13.7-cp27-cp27m-win_amd64.whl. Always through CMD opened on that path as showed in step 2
5- After step 4 when I imported OpenCV using import cv2 I didn't have the DLL error anymore but an error related to numpy (since I had just installed that version of Python and so Numpy wasn't installed yet). I installed numpy by typing pip install numpy and voilà ! The problem was solved and OpenCV imported correctly.
Hope this helps someone.
In my case, I had to install an older version of openCV (windows 10, Python 3.6.8)
pip install opencv-python==3.3.0.9
This error can be caused by missing the following dll
To have this dll install:
https://www.microsoft.com/en-us/software-download/mediafeaturepack
as already explained above
Running python 3.8.8 from windows 10 powershell from an anaconda 4.10.1 environment I installed opencv with
conda install opencv
I could import opencv no problem when I launched python from the command line.
However, when I tried to run code from inside pydev using the python interpreter for the specific anaconda environment I had activated, pydev couldn't find whichever dll it was looking for when importing opencv.
Setting the following environment variable resolved the issue:
CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1
Source: PyDev/Eclipse not loading _mklinit when run from a Conda environment
Which points to this trouble shooting description for a different library loading issue: https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#numpy-mkl-library-load-failed
If you are using a server or docker enviroment without a gui (e.g. Windows Core Server) make sure that you use the headless version of cv2:
pip install opencv-contrib-python-headless
I had the same problem, it seems openCV requires Windows Media Feature pack which is not installed on Windows 10 N by default, please install it using the following link:
https://www.microsoft.com/en-us/software-download/mediafeaturepack
Windows 11 N
This a final fix for the people who don't use anaconda.
simply there are missing DLL files, that's it
download the latest version of
https://sourceforge.net/projects/opencvlibrary/
Then after you extract it search for .dll files and copy all of them and paste into C:\Windows\System32 and approve for replacing.
That's it !
Install python using:
pip install opencv-python(It will take the latest version)
Make sure opencv-python is installed in path(\Python\Python36\Lib\site-packages),
you will find cv2 folder over there.
To check the version of cv2:
import cv2
print(cv2.__version__)

How do I install Python OpenCV through Conda?

I'm trying to install OpenCV for Python through Anaconda, but I can't seem to figure this out.
I tried
conda install opencv
conda install cv2
I also tried searching
conda search cv
No cigar. I ran across this which lists opencv as an included package:
http://docs.continuum.io/anaconda/pkgs.html
After running conda info I noticed my version is 3.4.1, but I couldn't seem to find any information about this version online. I'm pretty confused about this.
Am I missing something pretty obvious here? If opencv was available for a previous version of Anaconda, then why wouldn't it be available for the newer version? And why does that link only show me documentation for version 1.9.2?
You can install it using binstar:
conda install -c menpo opencv
conda install opencv currently works for me on UNIX/python2. This is worth trying first before consulting other solutions.
This worked for me (on Ubuntu and conda 3.18.3):
conda install --channel https://conda.anaconda.org/menpo opencv3
The command above was what was shown to me when I ran the following:
anaconda show menpo/opencv3
This was the output:
To install this package with conda run:
conda install --channel https://conda.anaconda.org/menpo opencv3
I tested the following in python without errors:
>>> import cv2
>>>
I have summarized my now fully working solution, OpenCV-Python - How to install OpenCV-Python package to Anaconda (Windows). Nevertheless I've copied and pasted the important bits to this post.
At the time of writing I was using Windows 8.1, 64-bit machine, Anaconda/ Python 2.x. (see notes below - this works also for Windows 10, and likely Python 3.x too).
NOTE 1: as mentioned mentioned by #great_raisin (thank you) in comment section however, this solution appears to also work for Windows 10.
NOTE 2: this will probably work for Anaconda/Python 3.x too. If you are using Windows 10 and Anaconda/Python 3.x, and this solution works, please add a comment below. Thanks! (Update: noting from comment "Working on Windows 10")
NOTE 3: depending on whether you are using Python 2.x or 3.x, just adjust the print statement accordingly in code snippets. i.e. in Python 3.x it would be print("hello"), and in Python 2.x it would be print "hello".
TL;DR
To use OpenCV fully with Anaconda (and Spyder IDE), we need to:
Download the OpenCV package from the official OpenCV site
Copy and paste the cv2.pyd to the Anaconda site-packages directory.
Set user environmental variables so that Anaconda knows where to find the FFMPEG utility.
Do some testing to confirm OpenCV and FFMPEG are now working.
(Read on for the detail instructions...)
Prerequisite
Install Anaconda
Anaconda is essentially a nicely packaged Python IDE that is shipped with tons of useful packages, such as NumPy, Pandas, IPython Notebook, etc. It seems to be recommended everywhere in the scientific community. Check out Anaconda to get it installed.
Install OpenCV-Python to Anaconda
Cautious Note: I originally tried out installing the binstar.org OpenCV package, as suggested. That method however does not include the FFMPEG codec - i.e. you may be able to use OpenCV, but you won't be able to process videos.
The following instruction works for me is inspired by this OpenCV YouTube video. So far I have got it working on both my desktop and laptop, both 64-bit machines and Windows 8.1.
Download OpenCV Package
Firstly, go to the official OpenCV site to download the complete OpenCV package. Pick a version you like (2.x or 3.x). I am on Python 2.x and OpenCV 3.x - mainly because this is how the OpenCV-Python Tutorials are setup/based on.
In my case, I've extracted the package (essentially a folder) straight to my C drive (C:\opencv).
Copy and Paste the cv2.pyd file
The Anaconda Site-packages directory (e.g. C:\Users\Johnny\Anaconda\Lib\site-packages in my case) contains the Python packages that you may import. Our goal is to copy and paste the cv2.pyd file to this directory (so that we can use the import cv2 in our Python codes.).
To do this, copy the cv2.pyd file...
From this OpenCV directory (the beginning part might be slightly different on your machine). For Python 3.x, I guess, just change the 2.x to 3.x accordingly.
# Python 2.7 and 32-bit machine:
C:\opencv\build\python\2.7\x84
# Python 2.7 and 64-bit machine:
C:\opencv\build\python\2.7\x64
To this Anaconda directory (the beginning part might be slightly different on your machine):
C:\Users\Johnny\Anaconda\Lib\site-packages
After performing this step we shall now be able to use import cv2 in Python code. BUT, we still need to do a little bit more work to get FFMPEG (video codec) to work (to enable us to do things like processing videos).
Set Environmental Variables
Right-click on "My Computer" (or "This PC" on Windows 8.1) → left-click Properties → left-click "Advanced" tab → left-click "Environment Variables..." button.
Add a new User Variable to point to the OpenCV (either x86 for 32-bit system or x64 for 64-bit system). I am currently on a 64-bit machine.
| 32-bit or 64 bit machine? | Variable | Value |
|---------------------------|--------------|--------------------------------------|
| 32-bit | `OPENCV_DIR` | `C:\opencv\build\x86\vc12` |
| 64-bit | `OPENCV_DIR` | `C:\opencv\build\x64\vc12` |
Append %OPENCV_DIR%\bin to the User Variable PATH.
For example, my PATH user variable looks like this...
Before:
C:\Users\Johnny\Anaconda;C:\Users\Johnny\Anaconda\Scripts
After:
C:\Users\Johnny\Anaconda;C:\Users\Johnny\Anaconda\Scripts;%OPENCV_DIR%\bin
This is it we are done! FFMPEG is ready to be used!
Test to confirm
We need to test whether we can now do these in Anaconda (via Spyder IDE):
Import OpenCV package
Use the FFMPEG utility (to read/write/process videos)
Test 1: Can we import OpenCV?
To confirm that Anaconda is now able to import the OpenCV-Python package (namely, cv2), issue these in the IPython console:
import cv2
print cv2.__version__
If the package cv2 is imported OK with no errors, and the cv2 version is printed out, then we are all good! Here is a snapshot:
(source: mathalope.co.uk)
Test 2: Can we Use the FFMPEG codec?
Place a sample input_video.mp4 video file in a directory. We want to test whether we can:
read this .mp4 video file, and
write out a new video file (can be .avi or .mp4 etc.)
To do this we need to have a test Python code, call it test.py. Place it in the same directory as the sample input_video.mp4 file.
This is what test.py may look like (I've listed out both newer and older version codes here - do let us know which one works / not work for you!).
(Newer version...)
import cv2
cap = cv2.VideoCapture("input_video.mp4")
print cap.isOpened() # True = read video successfully. False - fail to read video.
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter("output_video.avi", fourcc, 20.0, (640, 360))
print out.isOpened() # True = write out video successfully. False - fail to write out video.
cap.release()
out.release()
(Or the older version...)
import cv2
cv2.VideoCapture("input_video.mp4")
print cv2.isOpened() # True = read video successfully. False - fail to read video.
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter("output_video.avi",fourcc, 20.0, (640,360))
print out.isOpened() # True = write out video successfully. False - fail to write out video.
cap.release()
out.release()
This test is VERY IMPORTANT. If you'd like to process video files, you'd need to ensure that Anaconda / Spyder IDE can use the FFMPEG (video codec). It took me days to have got it working. But I hope it would take you much less time! :)
Note: One more very important tip when using the Anaconda Spyder IDE. Make sure you check the current working directory (CWD)!!!
Conclusion
To use OpenCV fully with Anaconda (and Spyder IDE), we need to:
Download the OpenCV package from the official OpenCV site
Copy and paste the cv2.pyd to the Anaconda site-packages directory.
Set user environmental variables so that Anaconda knows where to find the FFMPEG utility.
Do some testing to confirm OpenCV and FFMPEG are now working.
Good luck!
You can install OpenCV by running these commands in the Anaconda command prompt:
conda config --add channels conda-forge
conda install libopencv opencv py-opencv
Source:
https://github.com/conda-forge/opencv-feedstock
It doesn't seem like the page you linked includes opencv any more. (Funny, I do recall it being included at a previous point as well.)
In any case, installation of OpenCV into Anaconda, although unavailable through conda, is pretty trivial. You just need to download one file.
Download OpenCV from https://opencv.org/releases/ and extract
From the extracted folder, copy the file from the extracted directory: opencv/build/python/2.7/(either x86 or x64, depending on your Anaconda version)/cv2.pyd to your Anaconda site-packages directory, e.g., C:\Anaconda\Lib\site-packages
To get FFmpeg within opencv to work, you'll have to add the directory that FFmpeg is located in to the path (e.g., opencv/sources/3rdparty/ffmpeg). Then you'll have to find the DLL file in that folder (e.g., opencv_ffmpeg_64.dll) and copy or rename it to a filename that includes the opencv version you are installing, (e.g., opencv_ffmpeg249_64) for 2.4.9.
Now at the Python prompt you should be able to type "import cv2"...to verify that it works, type "print cv2.__version__", and it should print out the OpenCV version you downloaded.
In May 2019, the answer is as follows for MacOS:
conda update freetype
conda install opencv -c conda-forge
This updates libfreetype.6.dylib to 24.0.0 compatibility and installs OpenCV 4.1.0.
The following installs opencv from conda-forge (note: tried on Windows)
conda config --add channels conda-forge
conda install opencv
To install OpenCV in Anaconda, start up the Anaconda command prompt
and install OpenCV with
conda install -c https://conda.anaconda.org/menpo opencv3
Test that it works in your Anaconda Spyder or IPython console with
import cv2
You can also check the installed version using:
cv2.__version__
To install OpenCv with conda on Windows-64 and Python 3.5, the only one that worked for me is:
conda install -c conda-forge opencv=3.1.0
I think the easiest option that should work cross-platform and across various versions of Anaconda is
#Run Anaconda Prompt as an Administrator (on Windows) & execute the command below
#(you may need to use sudo on a Unix-Based or Mac system
#to have the needed permissions)
conda install -c conda-forge opencv
I had exactly the same problem, and could not get conda to install OpenCV. However, I managed to install it with the OpenCV installer you find at this site:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
His files are "Wheel" whl files that can be installed with pip, e.g.
pip install SomePackage-1.0-py2.py3-none-any.whl
in a command window. It worked with Spyder directly after executing this command for me. I have had the same experience with other packages, the above UC Irvine site is a gold mine.
it works on anaconda3 windows 10 I have already downloaded it at 5 December 2019.
Firstly, using this command:
pip install opencv-contrib-python
after that windows will ask for permission and try again:
pip install opencv-contrib-python --user
look at this it works!!
In my case, I've python 3.9
I did this in my conda env and it works :
pip install opencv-python==3.4.15.55
pip install opencv-contrib-python==3.4.15.55
I entered the following command in the command prompt:
conda install -c menpo opencv=2.4.11
This worked for me!!!
On Linux, as discussed here, the best way to get opencv at present is from loopbio at conda-forge:
conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv
If you have 'a modern CPU' there exists also a compiled version "enabling all modern CPU instruction set extensions [...] and against libjpeg-turbo":
conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv-turbo`
Two of the solutions mentioned in other answers don't work unconditionally:
The conda you get through conda install opencv or pip install opencv-python doesn't have gtk2 support, so you can't display images through imshow.
Conda built by Menpo (conda install -c menpo opencv3) has gtk2 support, but
they have only built OpenCV 3.2 for Python 3.5, not Python 3.6
Ubuntu 16.10 has deprecated libpng12, leading to a missing dependency and the following error when trying to import cv2: ImportError: libpng12.so.0: cannot open shared object file: No such file or directory, as discussed here
EDIT: #Yamaneko points out that as of 14 June 2017, "there is an issue with loopbio's OpenCV version 3.2.0. It silently fails to read and write videos. It is due to a combination of an upstream OpenCV issue in combination with an old GCC. More details here. There is a PR on its way to solve the issue."
I just installed conda 4.7.11 in Windows 10. OpenCV can be easily installed in Anaconda Navigator. After launching Navigator, click on Environments on the left panel. In the top drop-down, select Not installed. Then search for py-opencv, tick on the left checkbox to install it. It will install the dependent package libopencv. I use import cv2 in Spyder to access it.
Like others, I had issues with Python 3.5.1/Anaconda 2.4.0 on OS X 10.11..
But I found a compatible package here:
https://anaconda.org/menpo/opencv3
It can be installed via the command line like so:
conda install -c https://conda.anaconda.org/menpo opencv3
Worked like a charm. First time I've ever gotten OpenCV to work on 3.x!
Windows only solution. OpenCV 3.x pip install for Python 3.x
Download .whl file (cpMN where you have Python M.N). contrib includes OpenCV-extra packages. For example, assuming you have Python 3.6 and Windows 64-bit, you might download opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
From command prompt type:
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
You'll have a package in your conda list : opencv-python 3.2.0+contrib <pip>
Now you could test it (no errors):
>>> import cv2
>>>
Original source page where I took the information is here.
If conda install opencv or conda install -c https://conda.binstar.org/menpo opencv does not work, you can try to compile from the source.
Download the source from http://opencv.org/downloads.html, follow the install instruction in http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html, (maybe you can jump to the last part directly, 'Building OpenCV from Source Using CMake...), change the cmake command as following:
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/**/env/opencv-2.4.10 -D BUILD_NEW_PYTHON_SUPPORT=ON -D PYTHON_EXECUTABLE=/home/**/env/anaconda/bin/python -D PYTHON_INCLUDE_DIR=/home/**/env/anaconda/include/python2.7 -D PYTHON_LIBRARY=/home/**/env/anaconda/lib/libpython2.7.so -D PYTHON_PACKAGES_PATH=/home/**/env/anaconda/lib/python2.7/site-packages -D PYTHON_NUMPY_INCLUDE_DIRS=/home/**/env/anaconda/lib/python2.7/site-packages/numpy/core/include ..
make -j4
make install
You will find cv2.so in anaconda/lib/python2.7/site-packages.
Then:
import cv2
print cv2.__version__
It will print out 2.4.10.
My environment is GCC 4.4.6, Python 2.7 (anaconda), and opencv-2.4.10.
To install the OpenCV package with conda, run:
conda install -c menpo opencv3=3.1.0
https://anaconda.org/menpo/opencv3
Although not through Conda, and this is specific to Ubuntu, the easiest way to install OpenCV with all its contrib modules built in such as SIFT and SURF is to use:
pip install opencv-contrib-python
It supports Python2.7+ and Python 3.4+
If you choose not to have the contribs built in, you could instead do:
pip install opencv-python
You need to install the following dependencies below before you run those commands though:
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
This is a good tutorial on setting OpenCV on Ubuntu:
https://medium.com/#debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961
To insatll opencv without downgrading just hit out this in terminal
particularly the user of linux mint or Ubuntu based distro
conda install -c conda-forge opencv
Hence go with it I am pretty sure that this will not disappoint you.
An easy and straight forward solution is to install python3.5 first before installing opencv3
conda install python=3.5
followed by
conda install --channel https://conda.anaconda.org/menpo opencv3
The correct command for installing the current version of OpenCV 3.3 in Anaconda windows:
conda install -c conda-forge opencv
or
conda install -c conda-forge/label/broken opencv
For 3.2 use this:
conda install -c menpo opencv3
I tried following command and it works fine
conda install -c conda-forge opencv
once you hit the command it will ask for yes or no
If you select yes it will proceed and install all the required packages
One thing i think nobody mentioned is that if you are using Windows N or KN edition, please install Media Feature Pack that is used for OpenCV.
Also make sure you have Visual C++ Distributable
installed.
And then you can use command
conda install -c menpo opencv
The following command works for me too. I am using an embedded IPython Notebook in Anaconda.
conda install -c https://conda.binstar.org/menpo opencv
I have just tried on two Win32 Python 3.5 computers. At first, I was able to conda install opencv, but it didn't work nor did the version from menpp, but this did:
conda install -c https://conda.binstar.org/conda-forge opencv
I had steps in repo that will help you properly install OpenCV.
If the links if broken, see this.
For requirements and prerequisites follow this instructions:
YOU NEED TO HAVE WINDOWS OS to begin this project.
windows 7 to 10
Follow the steps carefully
Install Anaconda2 32/64 python 2
or
Install Anaconda3 32/64 python 3
It Depends on System Information
Along the way you must check all the options ignore the red text
Then wait till installation completed ...
Open CMD admin when finish installed
Make sure that the anaconda-python is configured in CMD admin
Type: python
This will come out:
C:\WINDOWS\system32>python Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45)
[MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
Next is to install packages:
Numpy
OpenCV
PyMySQL or pymysql
Install and Import OpenCV
conda install -c conda-forge opencv = (version optional)
(click yes if there's updates)
Install and Import Numpy
pip install numpy
(click yes if there's updates)
Install and Import PyMySQL/pymysql
pip install PyMySQL or pymysql
When all the package is completely installed, then you must Reboot it.
go to CMD admin again
type "python"
import cv2 (cv2 is OpenCV)
import Numpy or numpy
import pymysql
import os
from PIL from Image
if all of then is ok.. your ready to run the code!!
After you finish all the steps, you can now test the code in SPYDER python that I use

Categories

Resources