Python Question

how to install Open CV for Python 3.x in windows 8.1?

I am trying to install and run OpenCV 3.0.0 for python 3.4.2, in windows 8.1


  1. I have downloaded the OpenCV file from here http://opencv.org/

  2. Extracted the folder in C:\

  3. I went to System->Advanced System Settings->Advanced->Environment variables

  4. add a new variable in "User Variables frame" name it "OPENCV_DIR" with value "c:\opencv\build\x64\vc12"

  5. add this at the end of Path ";C:\opencv;C:\opencv\build;%OPENCV_DIR%\bin"

  6. took this archive "cv2.pyd" from "C:\opencv\build\python\2.7\x64", copy it

  7. paste it in C:\Python34\Lib\site-packages



finally I went to the IDLE of python 3.4.2 and wrote

(this happened before copying the fine into the python directory)

import cv2
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
ImportError: No module named 'cv2'


and this happened after I copied the file into the python directory

import cv2
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import cv2
ImportError: DLL load failed: The specified module could not be found.


can somebody help me what I am doing wrong, I not sure whether I should install CMake and Numpy

also I am not sure how to use this webpage (recommended by so many people)
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
where many python libraries are abailable, including PIL, OpenCV, VideoCapture etc...

I want to try to run the examples from here
https:// realpython .com/blog/python/face-detection-in-python-using-a-webcam/

https:// www. youtube .com/watch?v=Czb9lOG4Swg&list=PLEmljcs2yU0wHqeLlrytfuiqyNKTKIlOq&index=2

http:// www. daveperrett .com/articles/2010/12/14/face-detection-with-osx-and-python/

EDIT

Ok, I should not use the file from python 27 in python 3.4, it wont work, I delete it, so as otterb suggested, I just install opencv_python‑3.0.0‑cp34‑none‑win_amd64.whl package from http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
but this file is an .whl not an exe file, and according to How do I install a Python package with a .whl file?

I followed this steps


  1. go to the command prompt

  2. change directory with "cd" to where I downloaded the file

  3. and write "pip install opencv_python-3.0.0-cp34-none-win_amd64.whl"



but I got the following message in red

Installing collected packages: opencv-python
Cleaning up...
Exception:
Traceback (most recent call last):
File "C:\Python34\lib\shutil.py", line 370, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is
being used by another process: 'C:\\Users\\JOSEFG~1\\AppData\\Local\\Temp\\pip-n
kyo0c6u-build\\opencv_python-3.0.0.data\\data\\Lib\\site-packages\\cv2.pyd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pip\commands\install.py", line 283, in run

requirement_set.install(install_options, global_options, root=options.root_p
ath)
File "C:\Python34\lib\site-packages\pip\req.py", line 1444, in install
requirement.remove_temporary_source()
File "C:\Python34\lib\site-packages\pip\req.py", line 761, in remove_temporary
_source
rmtree(self._temp_build_dir)
File "C:\Python34\lib\site-packages\pip\util.py", line 43, in rmtree
onerror=rmtree_errorhandler)
File "C:\Python34\lib\shutil.py", line 477, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 372, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python34\lib\site-packages\pip\util.py", line 53, in rmtree_errorhandler
(exctype is PermissionError and value.args[3] == 5) #python3.3
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python34\lib\shutil.py", line 370, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\JOSEFG~1\\AppData\\Local\\Temp\\pip-nkyo0c6u-build\\opencv_python-3.0.0.data\\data\\Lib\\site-packages\\cv2.pyd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Python34\lib\site-packages\pip\commands\install.py", line 302, in run

requirement_set.cleanup_files(bundle=self.bundle)
File "C:\Python34\lib\site-packages\pip\req.py", line 1319, in cleanup_files
req.remove_temporary_source()
File "C:\Python34\lib\site-packages\pip\req.py", line 761, in remove_temporary_source
rmtree(self._temp_build_dir)
File "C:\Python34\lib\site-packages\pip\util.py", line 43, in rmtree
onerror=rmtree_errorhandler)
File "C:\Python34\lib\shutil.py", line 477, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Python34\lib\shutil.py", line 372, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python34\lib\site-packages\pip\util.py", line 53, in rmtree_errorhandler
(exctype is PermissionError and value.args[3] == 5) #python3.3
IndexError: tuple index out of range

Storing debug log for failure in C:\Users\me\pip\pip.log


which means after reading it carefully that the file is unsafe to install in my pc

EDIT

also it seems that pip should be the latest one to run the previous command according to
How to install pip on Windows?
then I just upgrade pip in the command prompt with

python -m pip install -U pip


now I have version 7.1, I know it by writing

pip --version


then I tried again

pip install opencv_python-3.0.0-cp34-none-win_amd64.whl


but it seems that it is wroking as i am getting this message

C:\Users\Jose F Gomez D\Downloads>pip install opencv_python-3.0.0-cp34-none-win_amd64.whl
Requirement already satisfied (use --upgrade to upgrade): opencv-python==3.0.0 from file:///C:/Users/Jose%20F%20Gomez%20D/Downloads/opencv_python-3.0.0-cp34-none-win_amd64.whl in c:\python34\lib\site-packages


then I write in the python shell "import cv2" but there is a new error

ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
ImportError: numpy.core.multiarray failed to import


so I installed the numpy (and scipy just in case) library with

pip install numpy
pip install scipy


but it is not working as it requires C++

error microsoft visual c++ 10 is required

EDIT

I tried to find "microsoft visual c++ 2010 express" from the webpage of visal studio here https://www.visualstudio.com/, but There is no link to "microsoft visual c++ 2010 express", so I went to this site http://microsoft-visual-cpp-express.soft32.com/free-download/, download the file and execute it, now I got C++.

Again I went to the command prompt and try to install numpy and scipy and it did not work, there is an error in the path

ValueError: ['path']


ok now I tried to install numpy ans scipy package from

http://sourceforge.net/projects/numpy/files/NumPy/

but it did not worked so, I went to Gohike
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
and install numpy ans scipy from the command prompt in administrator mode

pip install scipy‑0.16.0‑cp34‑none‑win_amd64.whl
pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl

now I tried to run cv but nothing,
ups its cv2 and it is working, I will write the answer next

Answer

if you like this answer please vote, pull me up please

The right way to install OpenCV 3.0.0 for python 3.4.2 windows 8.1

  1. go to http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
  2. download opencv, numpy and scipy

for me I needed

opencv_python-3.0.0-cp34-none-win_amd64.whl

scipy‑0.16.0‑cp34‑none‑win_amd64.whl

numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl

  1. download and install microsoft visual c++ 2010 express from http://microsoft-visual-cpp-express.soft32.com/free-download/
  2. open command prompt as administrator
  3. change directory like "cd C:\Users\me\Downloads" to where I downloaded the file
  4. copy and paste this "python -m pip install -U pip"
  5. then install the libraries copy and paste this

"pip install opencv_python-3.0.0-cp34-none-win_amd64.whl"

"pip install scipy‑0.16.0‑cp34‑none‑win_amd64.whl "

"pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl"

that is all

-------------> Tricky Python <------------