简体   繁体   English

python + opencv“ DLL加载失败”

[英]python + opencv “dll load failed”

I'm trying to install opencv on my machine as explained in the book: "Packtpub OpenCV Computer Vision with Python Apr 2013" 我正尝试按照以下书籍中的说明在计算机上安装opencv:“ Packtpub OpenCV Computer Vision with Python Apr 2013”

It says that in order to run kinect you need to compile openCV with some stuff in it, so I downloaded openCV .exe that extracts to a 3.2gb folder and proceeded with all the steps... 它说,要运行kinect,您需要使用其中的一些东西编译openCV,因此我下载了openCV .exe并将其解压缩到3.2gb文件夹,然后执行所有步骤...

Used CMaker, used the compiler MinGW, and everything as the book said 如书所说,使用了CMaker,使用了编译器MinGW,以及所有内容

Than it tells me to try running some examples... but when I try to run drawing.py as recommended by the book, and all the others, it says: 比它告诉我尝试运行一些示例...但是,当我尝试按书中建议的方式运行drawing.py以及所有其他示例时,它说:

python drawing.py python drawing.py


OpenCV Python version of drawing OpenCV Python版本的绘图

traceback< most recent call last>: traceback <最近一次呼叫last>:

File "drawing.py", line 7, in 文件“ drawing.py”,第7行

import cv2.cv as cv

ImportError: DLL load failed: Invalid access to memory location. ImportError:DLL加载失败:对内存位置的无效访问。


I saw a lot of people saying this problem is fixed by adding the path to the bin of openCV dlls to path... 我看到很多人说通过将openCV dll bin的路径添加到path可以解决此问题...

how do I find out which dll name is missing so I can find the name of it and find the folder where it is? 如何找出缺少的dll名称,以便找到它的名称并找到它所在的文件夹?

I have a x64 computer but the book tells me to install everything x86 because it is harder to get some minor bugs, maybe a version incompatibility between openCV, compiler, cmaker, and python? 我有一台x64电脑,但是这本书告诉我要安装x86的所有内容,因为很难得到一些小错误,也许是openCV,编译器,cmaker和python之间的版本不兼容?

I've tried to add a lot of folders to "path" variable and it didn't work 我尝试将许多文件夹添加到“路径”变量中,但没有用

please tell me how I find out which dlls are missing so I can search for them on the computer or some other way to solve this problem because I'm just out of ideas 请告诉我如何找出缺少的dll,以便我可以在计算机上搜索它们或通过其他方法来解决此问题,因为我没有想法

I don't have a high enough rep to add a comment otherwise I would but something you can do is start python with the -v option. 我没有足够高的代表来添加评论,否则我会这样做,但是您可以做的是使用-v选项启动python。

doing that will add a bit more to the output console and it will cause the python VM to output where it is looking for things when it tries looking for things, especially when failures occur. 这样做会给输出控制台增加更多的东西,并且会导致python VM在尝试查找事物时将其输出到查找事物的位置,尤其是在发生故障时。 I've found that to be helpful when trying to hunt problems such as path problems down. 我发现这在尝试寻找诸如路径问题之类的问题时会很有帮助。

It also sounds like you haven't got your paths setup correctly. 听起来您还没有正确设置路径。 Have you looked at ImportError: DLL load failed: %1 is not a valid Win32 application ? 您是否查看过ImportError:DLL加载失败:%1不是有效的Win32应用程序 If a DLL was expected in a certain location but wasn't loaded or present but then 'called' via a LoadLibrary (without checking to see if it was actually loaded) that might cause such an error. 如果某个DLL在某个位置是预期的,但尚未加载或存在,但随后通过LoadLibrary(未检查是否实际加载)“调用”了,则可能导致这种错误。 It is probably the fault of the original DLL that failed to verify the subsequent DLL was loaded instead of just assuming the LoadLibrary call succeeded. 可能是原始DLL的错误,无法验证是否加载了后续DLL,而不仅仅是假设LoadLibrary调用成功。

In addition to the python -v yourmodule.py option you could also try running an strace (if you are on unix -- but it doesn't sound like you are). 除了python -v yourmodule.py选项之外,您还可以尝试运行strace(如果您使用的是unix,但听起来并不像是)。 I used to use SoftICE on Windows for digging down deep. 我曾经在Windows上使用SoftICE进行深入研究。 If you know the package or the DLL that is at the root of the problem, and have access to a dll export tool, you should be able to get a list of the dependencies the dll needs (external functions it relies on). 如果您知道问题的根源所在的软件包或DLL,并且可以访问dll导出工具,则应该能够获取dll需要的依赖项列表(它依赖的外部功能)。 Then you just need to know or find those functions it relies on from other DLLs. 然后,您只需要了解或找到其他DLL依赖的功能即可。 It's been awhile since I used to had do this sort of stuff all the time to locate functions in other DLLs but it is something that is entirely doable from a spelunkers perspective. 自从我一直以来一直在做此类工作以在其他DLL中定位函数以来,已经有一段时间了,但是从spelunkers的角度来看,这是完全可行的。 But there are probably easier ways to go about it. 但是可能有更简单的方法可以解决此问题。

I'd start with the python -v approach first. 我先从python -v方法开始。

The DLLs you need are almost certainly the ones kept in opencv/build/x64/vc11/bin (this path will be different, but equivalent, based on whatever compiler you used). 几乎可以肯定,您需要的DLL是保存在opencv / build / x64 / vc11 / bin中的(根据您使用的编译器,此路径将有所不同,但等效)。 That's the only folder that needs to be added to your system path. 那是唯一需要添加到系统路径的文件夹。

Make sure that if you have a 32-bit version of Python, you compile OpenCV with a 32-bit compiler. 确保如果您具有32位版本的Python,则使用32位编译器编译OpenCV。 Open up Python and it tells you its architecture. 打开Python,它会告诉您它的体系结构。

Also, try installing numpy+mkll instead of numpy from the link of binary packages binary package for numpy+mkll . 另外,尝试从numpy + mkll的二进制包二进制包链接中安装numpy + mkll而不是numpy。 I had the same error and this solution solved the problem for me. 我有同样的错误,此解决方案为我解决了问题。

if you have installed simple numpy, don't worry, open cmd in the directory where you downloaded the new package. 如果您已经安装了简单的numpy,请放心,在下载新软件包的目录中打开cmd。 use this: 用这个:

pip install name_of_the_whl_file 

or 要么

pip3 install name_of_the_whl_file

it will automatically uninstall the old numpy and install numpy + mkll . 它将自动卸载旧的numpy并安装numpy + mkll Also, always remmember to add import numpy statement in your code before import cv2 statement. 另外,请始终记住在导入cv2语句之前在代码中添加import numpy语句。

import numpy import cv2

Hope it helps. 希望能帮助到你。

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

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