问题
I have this issue where I try to import cv2 on python and get the following error message.
>>> import cv2
Traceback (most recent call last):
File \"<stdin>\", line 1, in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application.
I do understand there are many posts about this where it is suggested that the bitness of the package is different from the python package.
However, everything I am running is 64 bits. I am on win7 64 bits, I have the winpython 2.7.3.3, 64 bits distribution, and I compiled opencv in 64 bits with the instruction provided here and placed the cv2.pyd dll in the Lib/site-packages folder of python.
Unfortunately the suggestion of using the 32 bits version of python isn\'t working for me anymore as I have to handle numpy arrays too large for 32 bits.
Thanks!!!
------ UPDATE
The only thing missing was to add the new opencv binaries path (C:\\opencv\\build\\bin\\Release) to the Windows PATH environment variable, restart python.
Everything seems to be working fine now!
回答1:
The ImportError message is a bit misleading because of the reference to Win32, whereas the problem was simply the opencv DLLs were not found.
This problem was solved by adding the path the opencv binaries to the Windows PATH environment variable (as an example, on my computer this path is : C:\opencv\build\bin\Release).
回答2:
You could try installing the 32 bit version of opencv
回答3:
Or you have to rebuild the cv2 module for win 64bit.
回答4:
I just hit this and the problem was that the package had at one point been installed in the per-user packages directory. (On Windows.) aka %AppData%\Python. So Python was looking there first, finding an old 32-bit version of the .pyd file, and failing with the listed error. Unfortunately pip uninstall by itself wasn't enough to clean this, and at this time pip 10.0.1 doesn't seem to have a --user parameter for uninstall, only for install.
tl;dr Deleting the old .pyd from %AppData%\python\python27\site-packages resolved this problem for me.
回答5:
All you have to do is copy the cv2.pyd file from the x86 folder (C:\opencv\build\python\2.7\x86\ for example) to C:\Python27\Lib\site-packages\ , not from the x64 folder.
Hope that help you.
回答6:
When I had this error, it went away after I my computer crashed and restarted. Try closing and reopening your IDE, if that doesn't work, try restarting your computer. I had just installed the libraries at that point without restarting pycharm when I got this error.
Never closed PyCharm first to test because my blasted computer keeps crashing randomly... working on that one, but it at least solved this problem.. little victories.. :).
来源:https://stackoverflow.com/questions/14629818/importerror-dll-load-failed-1-is-not-a-valid-win32-application