导入错误:DLL 加载失败:找不到指定的过程。Python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22221427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: DLL load failed: The specified procedure could not be found. Python
提问by Sanchit
Recently, I have installed a current version of Python(x,y) package (2.7.6.0) and now when I run my python code, it shows an error:
最近,我安装了当前版本的 Python(x,y) 包 (2.7.6.0),现在当我运行我的 python 代码时,它显示一个错误:
Traceback (most recent call last):
File "D:\Projects\comparison\Lagebestimmung\main.py", line 11, in <module>
import cv2
ImportError: DLL load failed: The specified procedure could not be found.
I correctly selected opencv module during the installation.
我在安装过程中正确选择了 opencv 模块。
Also, I use to have an older version of Python(x,y) before in my computer which I uninstalled before installing the new version. In that version, there was no such problem.
此外,我以前在我的计算机中使用过旧版本的 Python(x,y),我在安装新版本之前将其卸载。在那个版本中,没有这样的问题。
回答by Priyank Patel
Try this: Install opencv for windows. download it at here :
试试这个:为 Windows 安装 opencv。在这里下载:
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.1/OpenCV-2.4.1.exe/download
Then
然后
Copy cv2.pyd from C:\opencv\build\python\x86.7\ and paste it in the folder python site-packages folder . restart your IDE.
Make sure numpy is installed. If not , get it from here ..
确保安装了 numpy。如果没有,请从这里获取..
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
回答by ogurets
- Use Dependency Walker (http://www.dependencywalker.com/) on your cv2.pyd from 'site-packages'.
- Look at the higher-left corner, where the library tree is.
- Normal libraries have blue or gray icons, find libraries with red icons on the left, like this: http://i.stack.imgur.com/YiEuD.png.
- Find API's having a red flag and remember parentlibrary names of the libraries with red icon. Red flag means that parent library requires some API, which is absent in the underlying library. In my case a library with the red icon is 'kernel32.dll', and it's parent libraries are msvcr90.dll, tbb.dll and the library from 'winsxs', which name's is obscured.
- Usually a problem can be solved by obtaining correct versions of the parent libraries. For example, you are trying to use a DLL, which is compiled for Windows Vista, on Windows XP. This DLL imports a 'InitializeCriticalSectionEx' API, which is absent in Windows XP's 'kernel32.dll'. Obtaining the XP version of your DLL or recompiling it with 'InitializeCriticalSection' instead of 'Ex' will solve the problem. Another example: you are using OpenCV compiled for use with Qt 4.8.4 and PyQt4, which contains Qt version 4.7. cv2.pyd (which is a DLL, by the way) will refuse to import because certain Qt API's required in your OpenCV are not available in 4.7's DLL's. The solution is to put Qt libraries version 4.8.4 into your '%PYTHONHOME%\Lib\site-packages\PyQt4' folder or PATH. I encountered this problem myself when building my own version of OpenCV from git repo.
- 在“site-packages”中的 cv2.pyd 上使用 Dependency Walker ( http://www.dependencywalker.com/)。
- 查看左上角,图书馆树所在的位置。
- 普通库有蓝色或灰色图标,找到左边有红色图标的库,像这样:http: //i.stack.imgur.com/YiEuD.png。
- 查找带有红色标志的 API,并记住带有红色图标的库的父库名称。危险信号意味着父库需要一些 API,而底层库中不存在这些 API。在我的例子中,带有红色图标的库是“kernel32.dll”,它的父库是 msvcr90.dll、tbb.dll 和来自“winsxs”的库,其名称被掩盖了。
- 通常可以通过获取正确版本的父库来解决问题。例如,您尝试在 Windows XP 上使用为 Windows Vista 编译的 DLL。此 DLL 导入了“InitializeCriticalSectionEx”API,Windows XP 的“kernel32.dll”中没有该 API。获取 DLL 的 XP 版本或使用“InitializeCriticalSection”而不是“Ex”重新编译它可以解决问题。另一个示例:您正在使用为与 Qt 4.8.4 和 PyQt4 一起使用而编译的 OpenCV,其中包含 Qt 4.7 版。cv2.pyd(顺便说一下,这是一个 DLL)将拒绝导入,因为 OpenCV 中所需的某些 Qt API 在 4.7 的 DLL 中不可用。解决方案是将 Qt 库版本 4.8.4 放入您的“%PYTHONHOME%\Lib\site-packages\PyQt4”文件夹或路径中。
回答by Oded BD
I had the same problem and when i use ipython [just write ipython at cmd if you have ipython installed] it works.
我遇到了同样的问题,当我使用 ipython [如果你安装了 ipython,就在 cmd 中写 ipython] 它可以工作。
回答by Luis Jose
the following worked for me. Assuming that Python(X,Y) is installed (and the option for OpenCV was checked at the beginning of the installation), I did the following steps:
以下对我有用。假设安装了 Python(X,Y)(并且在安装开始时检查了 OpenCV 的选项),我做了以下步骤:
- Download opencv-2.4.13, and extract file in a given folder.
- Copy file "cv2.pyd" (which is a file of 10MB)
- Replace the file cv2.pyd in the "...\Lib\site-packages" folder. You will notice that the original "cv2.pyc" file size is below 2MB.
- Start Python(x,y) and the Spyder. Type "cv2.version" in the Python console. You may get >>> cv2.version-> '2.4.13'
- OpenCV is now working!
- 下载 opencv-2.4.13,并在给定文件夹中提取文件。
- 复制文件“cv2.pyd”(这是一个10MB的文件)
- 替换“...\Lib\site-packages”文件夹中的文件 cv2.pyd。您会注意到原始“cv2.pyc”文件大小低于 2MB。
- 启动 Python(x,y) 和 Spyder。键入“CV2。版本在Python控制台”。你可能会得到 >>> cv2。版本-> '2.4.13'
- OpenCV 现在可以工作了!
回答by djondal
For programmers using python 3, download a wheel package in order to install OpenCV.
对于使用python 3的程序员,下载一个wheel包以安装OpenCV。
You will need to make sure that NumPy is already installed. Anaconda is a nice package to handle dependencies. You would get numpy out of the box with it.
您需要确保已经安装了 NumPy。Anaconda 是一个很好的处理依赖关系的包。你会用它来开箱即用。
Then, download the OpenCV version corresponding to your Python installation versionfrom : http://www.lfd.uci.edu/~gohlke/pythonlibs/
然后,从以下位置下载与您的 Python 安装版本相对应的 OpenCV 版本:http: //www.lfd.uci.edu/~gohlke/pythonlibs/
You can find the version of your Python interpreter by running:
您可以通过运行以下命令找到 Python 解释器的版本:
python --version
In my case as I run C-Python 3.5, I chose : opencv_python?3.2.0?cp35?cp35m?win_amd64.whl
在我的情况下,当我运行 C-Python 3.5 时,我选择了: opencv_python?3.2.0?cp 35?cp 35m?win_amd64.whl
Finally, in the directory you have downloaded the wheel package, run:
最后,在你下载了wheel包的目录中,运行:
pip install opencv_python-3.X.X-cpXX-cpXXm-xxxx.whl

