【发布时间】:2015-11-11 12:40:48
【问题描述】:
我正在尝试在 Windows 8.1 中为 python 3.4.2 安装和运行 OpenCV 3.0.0。
- 我已经从http://opencv.org/下载了OpenCV文件。
- 解压C:中的文件夹。
- 我去了系统 → 高级系统设置 → 高级 → 环境变量
- 在“用户变量框架”中添加一个新变量。将其命名为“OPENCV_DIR”,值为“c:\opencv\build\x64\vc12”。
- 在路径末尾添加:“;C:\opencv;C:\opencv\build;%OPENCV_DIR%\bin”
- 我从“C:\opencv\build\python\2.7\x64”中取出存档“cv2.pyd”并复制了它。
- 我已将其粘贴到
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'
这发生在我将文件复制到 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.
我做错了什么?我不确定是否应该安装 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 包,但是这个文件是 .whl 不是 EXE 文件,并且根据 How do I install a Python package with a .whl file? 我按照以下步骤操作:
转到命令提示符
使用“cd”将目录更改为我下载文件的位置
并写“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
这意味着仔细阅读后,该文件无法安全地安装在我的 PC 上。
另外,根据How do I install pip on Windows?,似乎 pip 应该是运行上一个命令的最新命令。然后我只是在命令提示符下升级 pip
python -m pip install -U pip
现在我有 7.1 版。我通过写作就知道了:
pip --version
然后我又试了一次
pip install opencv_python-3.0.0-cp34-none-win_amd64.whl
但是当我收到这条消息时,它似乎正在工作:
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
然后我在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
所以我安装了 numpy(和 scipy 以防万一)库
pip install numpy
pip install scipy
但它不工作,因为它需要 C++
错误 microsoft visual c++ 10 is required
我试图从https://www.visualstudio.com/的Visual Studio网页中找到“Visual C++ 2010 Express”,但是没有“Microsoft Visual C++ 2010 express”的链接,所以我去了页面http://microsoft-visual-cpp-express.soft32.com/free-download/,下载了文件,执行它,现在我得到了 C++。
我再次转到命令提示符并尝试安装 NumPy 和 SciPy,但没有成功。路径有错误:
ValueError: ['path']
好的,现在我尝试从以下位置安装 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
现在我尝试运行 cv,但什么也没有。 Uups,它是 cv2,它正在工作。接下来我会写答案。
【问题讨论】:
-
您似乎将python27的cv2复制到python34中。并且还要确保 python 和库都使用匹配的 32 位或 64 位版本。无论如何,我推荐来自 Gohlke 的安装程序。上次我使用 Gohkle 的安装程序在 win7 上的 64 位 python34 上安装 64 位 opencv,它对我有用。只需运行一个普通的windows exe,然后按照指示运行即可。
-
我复制了cv2 2.7版本,因为我没有任何其他选择,我将尝试使用Gohkle在64位python34上安装64位opencv,但它不是exe是.whl,怎么办我愿意吗?