如何在Windows 8.1上安装OpenCV for Python 3.x?

Jos*_*ila 3 python opencv numpy cmake

我正在尝试在Windows 8.1中安装并运行OpenCV 3.0.0 for python 3.4.2.

  1. 我从http://opencv.org/下载了OpenCV文件.
  2. 在C:中提取文件夹.
  3. 我进入了系统高级系统设置高级环境变量
  4. 在"用户变量框架"中添加新变量.将其命名为"OPENCV_DIR",其值为"c:\ opencv\build\x64\vc12".
  5. 在路径末尾添加:";; C:\ opencv; C:\ opencv\build;%OPENCV_DIR%\ bin"
  6. 我从"C:\ opencv\build\python\2.7\x64"中获取了存档"cv2.pyd"并将其复制.
  7. 我粘贴了C:\Python34\Lib\site-packages.

最后我去了Python 3.4.2的IDLE并写了(这是在将精美复制到Python目录之前发生的):

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

这是在我将文件复制到Python目录后发生的:

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.
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我不确定是否应该安装CMake和NumPy.

此外,我不知道如何使用这个网页(由很多人推荐), http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv,其中有许多Python库,包括PIL,OpenCV, VideoCapture等......

我想尝试运行以下示例:

好的,我不应该在Python 3.4中使用Python 2.7中的文件.它不会起作用.我删除了它,因为otterb建议,我刚从http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv安装了opencv_python-3.0.0-cp34-none-win_amd64.whl包,但是这个file是.whl而不是EXE文件,根据如何安装带有.whl文件的Python包?我按照以下步骤操作:

  1. 转到命令提示符

  2. 使用"cd"将目录更改为我下载文件的位置

  3. 并写上"pip install opencv_python-3.0.0-cp34-none-win_amd64.whl"

但我得到以下红色信息:

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
Run Code Online (Sandbox Code Playgroud)

这意味着仔细阅读后,该文件在我的电脑上安装是不安全的.

根据我如何在Windows上安装pip,似乎pip应该是运行上一个命令的最新版本?.然后我只需在命令提示符下升级pip

python -m pip install -U pip
Run Code Online (Sandbox Code Playgroud)

现在我有7.1版本.我写的是:

pip --version
Run Code Online (Sandbox Code Playgroud)

然后我再试一次

pip install opencv_python-3.0.0-cp34-none-win_amd64.whl
Run Code Online (Sandbox Code Playgroud)

但它似乎正在工作,因为我得到这个消息:

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
Run Code Online (Sandbox Code Playgroud)

然后我在python shell中写入"import cv2",但是有一个新的错误

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
Run Code Online (Sandbox Code Playgroud)

所以我安装了numpy(以及scipy以防万一)库

pip install numpy
pip install scipy
Run Code Online (Sandbox Code Playgroud)

但它不起作用,因为它需要C++

错误microsoft visual c ++ 10是必需的

我试图从Visual Studio的网页https://www.visualstudio.com/找到"Visual C++ 2010 Express" ,但是没有"Microsoft Visual C++ 2010 express"的链接,所以我去了http:/页面/microsoft-visual-cpp-express.soft32.com/free-download/,下载文件,执行它,现在我得到了C++.

我再次进入命令提示符并尝试安装NumPy和SciPy,但它无效.路径中存在错误:

ValueError: ['path']
Run Code Online (Sandbox Code Playgroud)

好的,现在我尝试从以下位置安装NumPy和SciPy软件包:

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

但它不起作用,所以我去了Gohike,http: //www.lfd.uci.edu/~gohlke/pythonlibs/#numpy,并在命令提示符下以管理员模式安装了NumPy和SciPy:

pip install scipy?0.16.0?cp34?none?win_amd64.whl
pip install numpy?1.9.2+mkl?cp34?none?win_amd64.whl
Run Code Online (Sandbox Code Playgroud)

现在我试着运行cv,但没有.Uups,它是cv2,它正在运作.接下来我会写下答案.

Jos*_*ila 10

在Windows 8.1上安装适用于Python 3.4.2的OpenCV 3.0.0的正确方法:

  1. 访问http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
  2. 下载OpenCV,NumPy和SciPy

对我来说,我需要:

  • 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. http://microsoft-visual-cpp-express.soft32.com/free-download/下载并安装Visual C++ 2010 Express
    2. 以管理员身份打开命令提示符
    3. 将目录如"cd C:\ Users\me\Downloads"更改为我下载文件的位置
    4. 复制并粘贴这个:"python -m pip install -U pip"
    5. 然后安装库.复制并粘贴此内容:

      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

就这些.

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