Reputation: 599
I am trying to install and run OpenCV 3.0.0 for python 3.4.2, in Windows 8.1.
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.
What am I 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 available, including PIL, OpenCV, VideoCapture, etc...
I want to try to run the examples from:
OK, I should not use the file from Python 2.7 in Python 3.4. It won't work. I deleted it, so as otterb suggested, I just installed the 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 these steps:
Go to the command prompt
Change directory with "cd" to where I downloaded the file
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 on my PC.
Also it seems that pip should be the latest one to run the previous command according to How do I 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 working 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
I tried to find "Visual C++ 2010 Express" from the webpage of Visual Studio at https://www.visualstudio.com/, but there is no link to "Microsoft Visual C++ 2010 express", so I went to page http://microsoft-visual-cpp-express.soft32.com/free-download/, downloaded the file, executed it, and now I got C++.
Again I went to the command prompt and tried 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 the NumPy and SciPy packages from:
http://sourceforge.net/projects/numpy/files/NumPy/
But it did not work, so I went to Gohike, http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy, and installed NumPy and 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. Uups, it's cv2, and it is working. I will write the answer next.
Upvotes: 3
Views: 10840
Reputation: 137
I did everything as mentioned by Jose Fernando Gomez Davila except I installed numpy before scipy as numpy is required to install scipy
pip install opencv_python-4.1.2-cp37-cp37m-win_amd64.whl
pip install scipy-1.4.1-cp37-cp37m-win_amd64.whl
pip install numpy-1.16.6+mkl-cp37-cp37m-win_amd64.whl
Upvotes: 0
Reputation: 1
I have successfully installed OpenCV 3.1.0 using conda
(install Anaconda 3 - 64 bit ) with the following command (conda installation of OpenCV 3):
conda install -c menpo opencv3=3.1.0
Please note that the only complete installation is obtained compiling the OpenCV libraries from the GitHub repository. I have found that some features (e.g. SURF detection) are missing from the conda installation and also from the wheels.
Upvotes: 0
Reputation: 599
The right way to install OpenCV 3.0.0 for Python 3.4.2 on Windows 8.1:
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
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 <------------
Upvotes: 10
Reputation: 2710
You can use pip to install the whl file like:
pip install path/to/whlfile
Yes, you are right. Gohlke's package used to be an EXE file file, but OpenCV is now distributed as whl. Sorry I missed that.
Here is a similar Stack Overflow question: How do I install a Python package with a .whl file?
Upvotes: 1