Python 导入错误:DLL 加载失败:%1 不是有效的 Win32 应用程序。但是DLL在那里
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19019720/
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: %1 is not a valid Win32 application. But the DLL's are there
提问by LarsH
I have a situation very much like the one at ImportError: DLL load failed: %1 is not a valid Win32 application, but the answer there isn't working for me.
我的情况非常像ImportError: DLL load failed: %1 is not a valid Win32 application,但那里的答案对我不起作用。
My Python code says:
我的 Python 代码说:
import cv2
But that line throws the error shown in the title of this question.
但是该行会引发此问题标题中显示的错误。
I have OpenCV installed in C:\lib\opencv
on this 64-bit machine. I'm using 64-bit Python.
我C:\lib\opencv
在这台 64 位机器上安装了 OpenCV 。我正在使用 64 位 Python。
My PYTHONPATH variable: PYTHONPATH=C:\lib\opencv\build\python\2.7
. This folder contains cv2.pyd
and that's all.
我的 PYTHONPATH 变量:PYTHONPATH=C:\lib\opencv\build\python\2.7
. 这个文件夹包含cv2.pyd
,仅此而已。
My PATH variable: Path=%OPENCV_DIR%\bin;...
This folder contains 39 DLL files such as opencv_core246d.dll
.
我的 PATH 变量:Path=%OPENCV_DIR%\bin;...
此文件夹包含 39 个 DLL 文件,例如opencv_core246d.dll
.
OPENCV_DIR has this value: OPENCV_DIR=C:\lib\opencv\build\x64\vc11
.
OPENCV_DIR 具有以下值:OPENCV_DIR=C:\lib\opencv\build\x64\vc11
。
The solution at ImportError: DLL load failed: %1 is not a valid Win32 applicationsays to add "the new opencv binaries path (C:\opencv\build\bin\Release
) to the Windows PATH environment variable". But as shown above, I already have the OpenCV binaries folder (C:\lib\opencv\build\x64\vc11\bin
) in my PATH. And my OpenCV installation doesn't have any Release folders (except for an empty one under build/java).
ImportError: DLL load failed: %1 is not a valid Win32 application的解决方案说要添加“新的 opencv 二进制文件路径 ( C:\opencv\build\bin\Release
) 到 Windows PATH 环境变量”。但如上所示,C:\lib\opencv\build\x64\vc11\bin
我的 PATH 中已经有 OpenCV 二进制文件文件夹 ( )。而且我的 OpenCV 安装没有任何 Release 文件夹(除了 build/java 下的一个空文件夹)。
Any ideas as to what's going wrong? Can I tell Python to verbosely trace the loading process? Exactly what DLL's is it looking for?
关于出了什么问题的任何想法?我可以告诉 Python 详细跟踪加载过程吗?它究竟在寻找什么 DLL?
Thanks, Lars
谢谢,拉斯
EDIT:
编辑:
I just noticed that, according to http://www.dependencywalker.com/, the cv2.pyd
in C:\lib\opencv\build\python\2.7
is 32-bit, whereas the machine and the Python I'm running are 64-bit. Could that be the problem? And if so, where can I find a 64-bit version of cv2.pyd?
我刚刚注意到,根据http://www.dependencywalker.com/,cv2.pyd
inC:\lib\opencv\build\python\2.7
是 32 位,而我正在运行的机器和 Python 是 64 位。这可能是问题吗?如果是这样,我在哪里可以找到 64 位版本的 cv2.pyd?
采纳答案by Kill Console
Unofficial Windows Binaries for Python Extension Packages
you can find any python libs from here
你可以从这里找到任何 python 库
回答by Clive Verghese
Please check if the python version you are using is also 64 bit. If not then that could be the issue. You would be using a 32 bit python version and would have installed a 64 bit binaries for the OPENCV library.
请检查您使用的 python 版本是否也是 64 位。如果没有,那么这可能是问题所在。您将使用 32 位 python 版本,并为 OPENCV 库安装了 64 位二进制文件。
回答by Amalgovinus
In my case, I have 64bit python, and it was lxml that was the wrong version--I should have been using the x64 version of that as well. I solved this by downloading the 64-bit version of lxml here:
就我而言,我有 64 位 python,而 lxml 是错误的版本——我也应该使用它的 x64 版本。我通过在此处下载 64 位版本的 lxml 解决了这个问题:
https://pypi.python.org/pypi/lxml/3.4.1
https://pypi.python.org/pypi/lxml/3.4.1
lxml-3.4.1.win-amd64-py2.7.exe
This was the simplest answer to a frustrating issue.
这是对令人沮丧的问题的最简单的回答。
回答by olive_tree
I just had this problem, it turns it was just because I was using x64 version of the opencv file. Tried the x86 and it worked.
我刚遇到这个问题,原来只是因为我使用的是 x64 版本的 opencv 文件。尝试了 x86 并且它有效。
回答by Autonomous
I copied cv2.pyd
file from /opencv/build/python/2.7/x86
folder instead of from /x64
folder to C:/Python27/Lib/site-packeges
. I followed rest of the instructions provided here.
我将cv2.pyd
文件从/opencv/build/python/2.7/x86
文件夹而不是从/x64
文件夹复制到C:/Python27/Lib/site-packeges
. 我遵循了此处提供的其余说明。
Added by someone else, not verified: I also copy file cv2.pyd
to folder C:/Python27/Lib/site-packages/cv2
. It works.
由其他人添加,未验证:我也将文件复制cv2.pyd
到文件夹C:/Python27/Lib/site-packages/cv2
. 有用。
回答by Al Lelopath
For me the problem was that I was using different versions of Python in the sameEclipse project. My setup was not consistent with the Project Propertiesand the Run ConfigurationPython versions.
对我来说,问题是我在同一个Eclipse 项目中使用了不同版本的 Python 。我的设置与项目属性和运行配置Python 版本不一致。
In Project > Properties > PyDev, I had the Interpreter set to Python2.7.11.
在Project > Properties > PyDev 中,我将 Interpreter 设置为 Python2.7.11。
In Run Configurations > Interpreter, I was using the Default Interpreter. Changing it to Python 2.7.11 fixed the problem.
在Run Configurations > Interpreter 中,我使用的是默认解释器。将其更改为 Python 2.7.11 解决了该问题。
回答by Ezekiel Kruglick
Wow, I found yet another case for this problem. None of the above worked. Eventually I used python's ability to introspect what was being loaded. For python 2.7 this means:
哇,我发现这个问题的另一个案例。以上都没有奏效。最终我使用了 python 的能力来检查正在加载的内容。对于 python 2.7,这意味着:
import imp
imp.find_module("cv2")
This turned up a completely unexpected "cv2.pyd" file in an Anaconda DLL directory that wasn't touched by multiple uninstall/install attempts. Python was looking there first and not finding my good installation. I deleted that cv2.pyd file and tried imp.find_module("cv2") again and python immediately found the right file and cv2 started working.
这在 Anaconda DLL 目录中出现了一个完全意外的“cv2.pyd”文件,该文件未被多次卸载/安装尝试触及。Python首先在那里寻找并没有找到我的良好安装。我删除了那个 cv2.pyd 文件并再次尝试了 imp.find_module("cv2") 并且 python 立即找到了正确的文件并且 cv2 开始工作。
So if none of the other solutions work for you, make sure you use python introspection to see what file python is trying to load.
因此,如果其他解决方案都不适合您,请确保您使用 python 自省来查看 python 尝试加载的文件。
回答by Michael Ye
I found the solution, maybe you can try to use the cmd window rather than the anaconda prompt window to start you first scrapy test.
我找到了解决方案,也许您可以尝试使用cmd窗口而不是anaconda提示窗口来开始您的第一个scrapy测试。
回答by alireza
First I copied cv2.pyd
from /opencv/build/python/2.7/x86
to C:/Python27/Lib/site-packeges
. The error was
首先,我cv2.pyd
从复制/opencv/build/python/2.7/x86
到C:/Python27/Lib/site-packeges
。错误是
"RuntimeError: module compiled against API version 9 but this version of numpy is 7"
“运行时错误:针对 API 版本 9 编译的模块,但此版本的 numpy 是 7”
Then I installed numpy-1.8.0-win32-superpack-python2.7.exe
and opencv works fine.
然后我安装了numpy-1.8.0-win32-superpack-python2.7.exe
并且 opencv 工作正常。
>>> import cv2
>>> print cv2.__version__
2.4.13
回答by MatrixManAtYrService
If your build-system (CMake in my case) copies the file from <name>.dll
to <name>.pyd
, you will get this error if the original file wasn't actually a dll. In my case, building shared libraries got switched off, so the underlying file was actually a *.lib
.
如果您的构建系统(在我的情况下为 CMake)将文件从<name>.dll
to复制<name>.pyd
,如果原始文件实际上不是 dll,您将收到此错误。就我而言,构建共享库已关闭,因此底层文件实际上是*.lib
.
I discovered this error by loading the pyd
file in DependencyWalkerand finding that it wasn't valid.
我通过pyd
在DependencyWalker 中加载文件并发现它无效来发现此错误。