问题:ImportError:DLL加载失败:%1不是有效的Win32应用程序。但是DLL在那里

我的情况非常类似于ImportError上的情况:DLL加载失败:%1不是有效的Win32应用程序,但是答案对我不起作用。

我的Python代码说:

import cv2

但是该行引发了此问题标题中显示的错误。

C:\lib\opencv在这台64位计算机上安装了OpenCV 。我正在使用64位Python。

我的PYTHONPATH变量:PYTHONPATH=C:\lib\opencv\build\python\2.7。该文件夹包含cv2.pyd所有内容。

我的PATH变量:Path=%OPENCV_DIR%\bin;...此文件夹包含39个DLL文件,例如opencv_core246d.dll

OPENCV_DIR具有以下值:OPENCV_DIR=C:\lib\opencv\build\x64\vc11

ImportError上的解决方案:DLL加载失败:%1不是有效的Win32应用程序,表示要向C:\opencv\build\bin\ReleaseWindows PATH环境变量添加新的opencv二进制路径()。但是,如上所示,C:\lib\opencv\build\x64\vc11\bin我的PATH中已经有OpenCV Binaries文件夹()。而且我的OpenCV安装没有任何Release文件夹(build / java下为空)。

关于出什么问题有什么想法吗?我可以告诉Python详细跟踪加载过程吗?究竟要寻找什么DLL?

谢谢,拉斯

编辑:

我只注意到,根据http://www.dependencywalker.com/中,cv2.pydC:\lib\opencv\build\python\2.7为32位,而我运行的机器和Python的是64位。可能是问题所在吗?如果是这样,我在哪里可以找到cv2.pyd的64位版本?

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.

My Python code says:

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.

My PYTHONPATH variable: PYTHONPATH=C:\lib\opencv\build\python\2.7. This folder contains cv2.pyd and that’s all.

My PATH variable: Path=%OPENCV_DIR%\bin;... This folder contains 39 DLL files such as opencv_core246d.dll.

OPENCV_DIR has this value: OPENCV_DIR=C:\lib\opencv\build\x64\vc11.

The solution at ImportError: DLL load failed: %1 is not a valid Win32 application says 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).

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?

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?


回答 0


回答 1

请检查您使用的python版本是否也是64位。如果没有,那可能就是问题所在。您将使用32位python版本,并且已为OPENCV库安装了64位二进制文​​件。

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.


回答 2

哇,我发现了这个问题的另一种情况。以上都不起作用。最终,我使用python的功能来内省正在加载的内容。对于python 2.7,这意味着:

import imp
imp.find_module("cv2")

这在Anaconda DLL目录中打开了一个完全意外的“ cv2.pyd”文件,多次卸载/安装尝试均未涉及该文件。Python首先是在那儿寻找的,却找不到我的好安装。我删除了该cv2.pyd文件,然后再次尝试imp.find_module(“ cv2”),python立即找到了正确的文件,并且cv2开始工作。

因此,如果没有其他解决方案对您有用,请确保您使用python内省来查看python尝试加载的文件。

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:

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.

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.


回答 3

就我而言,我有64位python,而lxml是错误的版本-我也应该一直使用x64版本。我通过在此处下载lxml的64位版本来解决此问题:

https://pypi.python.org/pypi/lxml/3.4.1

lxml-3.4.1.win-amd64-py2.7.exe

这是一个令人沮丧的问题的最简单答案。

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:

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.


回答 4

我只是遇到了这个问题,原来是因为我使用的是x64版本的opencv文件。尝试了x86,它起作用了。

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.


回答 5

如果您的构建系统(在我的情况下为CMake)将文件从复制<name>.dll<name>.pyd,则如果原始文件实际上不是dll,则会出现此错误。就我而言,构建共享库已关闭,因此基础文件实际上是一个*.lib

我通过将pyd文件加载到DependencyWalker中并发现它无效而发现了此错误。

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.

I discovered this error by loading the pyd file in DependencyWalker and finding that it wasn’t valid.


回答 6

我有同样的问题。这是我所做的:

  1. 我从这里下载pywin32 Wheel文件,然后

  2. 我卸载了pywin32模块。要卸载,请在命令提示符中执行以下命令。

    pip uninstall pywin32

  3. 然后,我重新安装了pywin32。要安装它,请在pywin32 wheel文件所在的目录中打开命令提示符。然后执行以下命令。

    pip install <Name of the wheel file with extension> 车轮文件将类似于:piwin32-XXX-cpXX-none-win32.whl

它为我解决了问题。您可能还想尝试一下。希望它也对您有用。

I had the same problem. Here’s what I did:

  1. I downloaded pywin32 Wheel file from here, then

  2. I uninstalled the pywin32 module. To uninstall execute the following command in Command Prompt.

    pip uninstall pywin32

  3. Then, I reinstalled pywin32. To install it, open the Command Prompt in the same directory where the pywin32 wheel file lies. Then execute the following command.

    pip install <Name of the wheel file with extension> Wheel file will be like: piwin32-XXX-cpXX-none-win32.whl

It solvs the problem for me. You may also like to give it a try. Hope it work for you as well.


回答 7

cv2.pyd/opencv/build/python/2.7/x86文件夹而不是从/x64文件夹复制文件到C:/Python27/Lib/site-packeges。我按照此处提供的其余说明进行操作。

由其他人添加,未经验证:我还复制了文件 cv2.pyd到folder C:/Python27/Lib/site-packages/cv2。有用。

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.

Added by someone else, not verified: I also copy file cv2.pyd to folder C:/Python27/Lib/site-packages/cv2. It works.


回答 8

对我来说,问题是我在同一个 Eclipse项目中使用了不同版本的Python 。我的设置与“ 项目属性”和“ 运行配置” Python版本不一致。

项目>属性> PyDev中,将解释器设置为Python2.7.11。

“运行配置”>“解释器”中,我正在使用“默认解释器”。将其更改为Python 2.7.11可解决此问题。

For me the problem was that I was using different versions of Python in the same Eclipse project. My setup was not consistent with the Project Properties and the Run Configuration Python versions.

In Project > Properties > PyDev, I had the Interpreter set to Python2.7.11.

In Run Configurations > Interpreter, I was using the Default Interpreter. Changing it to Python 2.7.11 fixed the problem.


回答 9

当我使用32位Windows Installer在系统上卸载并重新安装其他版本的2.7.x Python时,遇到了相同的问题。我的大多数导入语句都出现相同的错误。我卸载了新安装的Python,然后下载了64位Windows安装程序,然后再次重新安装了Python,它可以正常工作。希望对您有帮助。

I faced the same issue when I uninstalled and reinstalled a different version of 2.7.x of Python on my system using a 32 bit Windows Installer. I got the same error on most of my import statements. I uninstalled the newly installed Python and downloaded a 64 bit Windows installer and reinstalled Python again and it worked. Hope this helps you.


回答 10

所以我在Windows下安装vtk时遇到问题(由于我使用python 3.7,到目前为止,仅适用于较旧的python版本,没有可用的二进制文件pip install vtk无法正常工作)

我确实在cmd中编写了python:

Python 3.7.3 on win32

所以我现在知道我的python 3.7.3在32位上运行。

然后,我在下载了正确的车轮 VTK-8.2.0-cp37-cp37m-win32.whl

接下来,我安装了该轮子:

pip install VTK-8.2.0-cp37-cp37m-win32.whl

然后,我对其进行了测试并成功运行:

python
import vtk

So I had problems installing vtk under windows (as I use python 3.7 there is no binary available so far just for older python versions pip install vtk is not working)

I did wrote python in my cmd:

Python 3.7.3 on win32

So I now know I have python 3.7.3 runing on a 32 bit.

I then downloaded the correct wheel at VTK‑8.2.0‑cp37‑cp37m‑win32.whl

Next I instlled that wheel:

pip install VTK-8.2.0-cp37-cp37m-win32.whl

Then I tested it and it worked:

python
import vtk

回答 11

更新numpy。

pip install numpy --upgrade

为我工作!

Update numpy.

pip install numpy --upgrade

Work for me!!


回答 12

首先,我cv2.pyd从复制/opencv/build/python/2.7/x86C:/Python27/Lib/site-packeges。错误是

“ RuntimeError:模块是根据API版本9编译的,但此版本的numpy是7”

然后我安装了numpy-1.8.0-win32-superpack-python2.7.exeopencv,并且工作正常。

>>> import cv2
>>> print cv2.__version__
2.4.13

First I copied cv2.pyd from /opencv/build/python/2.7/x86 to C:/Python27/Lib/site-packeges. The error was

“RuntimeError: module compiled against API version 9 but this version of numpy is 7”

Then I installed numpy-1.8.0-win32-superpack-python2.7.exe and opencv works fine.

>>> import cv2
>>> print cv2.__version__
2.4.13

回答 13

您可以opencv官方非官方站点进行安装。

如果使用,请参考问题和问题Anaconda

You can install opencv from official or unofficial sites.

Refer to this question and this issue if you are using Anaconda.


回答 14

  1. 请确保您已安装python 2.7.12或更低版本,否则您肯定会收到此错误。
  2. 如果操作系统为64位,请确保已安装64位Oracle客户端。
  3. 确保用于Python 2.7的Microsoft Visual C ++编译器对于64位Os为64位,对于32位为32位。注意:-如果您的操作系统是64位,则安装所有64位软件包;如果操作系统是32位,则安装32位软件包。
  1. Please make sure that you have installed python 2.7.12 or below version otherwise you will get this error definitely.
  2. Make sure Oracle client is 64 bit installed if OS is 64 Bit.
  3. Make sure Microsoft Visual C++ Compiler for Python 2.7 is 64 for bit for 64 bit Os or 32 bit for 32 bit. Note:- IF ur OS is 64 bit install all package of 64 bit or if Os is 32 bit install 32 bit package.

回答 15

它有一个非常简单的解决方案。安装后的opencv 地方

cv2.pydC:\opencv\build\python\2.7\ **x64**C:\Python27\Lib\site-packages

代替,cv2.pydC:\opencv\build\python\2.7\ **x86**C:\Python27\Lib\site-packages

It has a very simple solution. After installing opencv place

cv2.pyd from C:\opencv\build\python\2.7\ **x64** to C:\Python27\Lib\site-packages

instead of, place cv2.pyd from C:\opencv\build\python\2.7\ **x86** to C:\Python27\Lib\site-packages


回答 16

尝试导入MySQLdb时出现此错误。

对我有用的是卸载Python,然后重新安装。

安装npm(https://www.npmjs.com/get-npm)后出现错误。它所做的一件事是即使我已经安装了Python,也要安装它。

I got this error when trying to import MySQLdb.

What worked for me was to uninstall Python and then reinstall it.

I got the error after installing npm (https://www.npmjs.com/get-npm). One thing it did was install Python even though I already had it.


回答 17

这对我有用。我尝试了不同的方法,但这是我最好的解决方案。

打开命令提示符并键入以下内容; pip install opencv-python。(确保您的互联网已打开)。之后,请尝试再次导入。

This has worked for me. I have tried different methods but this was my best solution.

Open command prompt and type the following; pip install opencv-python. (make sure your internet is on). after that try importing it again.


回答 18

这个跟我一起工作

pip install -- pywin32==227

This one worked with me

pip install -- pywin32==227

回答 19

我找到了解决方案,也许您可​​以尝试使用cmd窗口而不是anaconda提示窗口来开始您的第一笔测试。

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.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。