简体   繁体   English

Windows:Python + OpenCV + Qt:“导入cv2”显示“找不到dll”错误

[英]Windows: Python + OpenCV + Qt: “import cv2” gives “dll not found” error

I have a problem when I'm trying to use OpenCV (v3.1.0) in Python (v3.4). 当我尝试在Python(v3.4)中使用OpenCV(v3.1.0)时遇到问题。 To make things more complicated, OpenCV is built with the "contrib" package and Qt support (v5.5). 为了使事情变得更复杂,OpenCV内置了“ contrib”软件包和Qt支持(v5.5)。

This is what I did (this has some pitfalls on it's own, but those are out of the scope of this question): 这就是我所做的(这本身就有一些陷阱,但是这些不在此问题的范围之内):

  1. Install required software 安装所需的软件
    1. I installed WinPython (v3.4.4, 64 Bit version) 我安装了WinPython(v3.4.4,64位版本)
    2. I installed cmake (v3.6.0) 我安装了cmake(v3.6.0)
  2. Download sources 下载资源
    1. I downloaded the Qt sources from the GIT repo 我从GIT存储库下载了Qt来源
    2. I downloaded the OpenCV sources from the GIT repo 我从GIT存储库下载了OpenCV源代码
    3. I downloaded the OpenCV "contrib" sources from the GIT repo 我从GIT存储库下载了OpenCV“ contrib”资源
  3. build sources -> RELEASE, 64 Bit (!) 构建源代码-> RELEASE,64位(!)
    1. build Qt from sources 从源代码构建Qt
    2. build OpenCV from sources (with "contrib" modules) 从源代码构建OpenCV(带有“ contrib”模块)

cmake ( OpenCV 3.1.0 for python 3 ) already took care of copying the "cv2.pyd" to the "your/python/folder/Lib/site-modules" directory. cmake(适用于python 3的OpenCV 3.1.0)已经负责将“ cv2.pyd”复制到“ your / python / folder / Lib / site-modules”目录中。

Now I have the problem that calling "import cv2" from python gives the error " 现在,我遇到的问题是,从python调用“ import cv2”会产生错误“

>>> import cv2
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
import cv2
ImportError: DLL load failed: Module not found

How can I find out which module is missing and how to solve it? 如何找出缺少的模块以及如何解决?

What you may not want to do is just adding paths that are likely needed to your environment variables . 您可能不想做的只是添加环境变量可能需要的路径

There is a way to find out what is missing: 一个办法,找出哪些是缺失的:

  1. Download DependencyWalker 下载DependencyWalker
  2. open your "cv2.pyd" with the dependency walker 使用依赖项遍历器打开“ cv2.pyd”
  3. Analyze your file (starts automatically when you select your file) 分析文件(选择文件后自动启动)
  4. Hit "F9" such that it shows the full paths to the required DLLs 点击“ F9”,使其显示所需DLL的完整路径。
  5. Check, which DLL files are missing 检查哪些DLL文件丢失
  6. Copy them to those folders 将它们复制到那些文件夹

For me, it was the case that python/cv2.pyd searched to all the Qt DLLs in the folder where cv2.pyd is in. 对我来说,是python / cv2.pyd搜索cv2.pyd所在文件夹中的所有Qt DLL的情况。

I just copied them there and that was it. 我只是将它们复制到那里,仅此而已。

For Windows: 对于Windows:

Step 1. Download python installer from https://www.python.org/downloads/ ,install python by double clicking this file and check the option for adding python to PATH as in given image. 步骤1.从https://www.python.org/downloads/下载python安装程序,双击此文件安装python,并按照给定的图像检查将python添加到PATH的选项。

如图像中所示

Step 2. Download file "numpy‑1.15.4+mkl‑cp27‑cp27m‑win32.whl" from unofficial site . 步骤2.从非官方站点下载文件“ numpy‑1.15.4 + mkl‑cp27‑cp27m‑win32.whl”。

Go to this file's location open command prompt and type- 转到该文件的位置打开命令提示符,然后键入-

pip install numpy‑1.15.4+mkl‑cp27‑cp27m‑win32.whl

Now go to python IDLE and type: 现在转到python IDLE并输入:

import numpy

It should give no error. 它应该没有错误。

Step 3. Download file "scipy‑1.2.1‑cp27‑cp27m‑win32.whl" from unofficial site . 步骤3.从非官方站点下载文件“ scipy‑1.2.1‑cp27‑cp27m‑win32.whl”。

Go to this file's location open command prompt and type- 转到该文件的位置打开命令提示符,然后键入-

pip install scipy‑1.2.1‑cp27‑cp27m‑win32.whl

Now go to python IDLE and type: 现在转到python IDLE并输入:

import scipy

It should give no error. 它应该没有错误。

step 4 : Download file "opencv_python‑2.4.13.7‑cp27‑cp27m‑win32.whl" from unofficial site . 步骤4:从非官方站点下载文件“ opencv_python‑2.4.13.7‑cp27‑cp27m‑win32.whl”。

Go to this file's location open command prompt and type- 转到该文件的位置打开命令提示符,然后键入-

pip install opencv_python‑2.4.13.7‑cp27‑cp27m‑win32.whl

Now go to python IDLE and type: 现在转到python IDLE并输入:

import cv2

It should give no error, means opencv installed successfully in windows. 它应该没有错误,这意味着在Windows中成功安装了opencv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM