Python-Tesseract ImportError: DLL load failed: %1 is not a valid Win32 applicati

133 阅读3分钟

当尝试将 python-tesseract 导入到项目(OCR 功能)中时,出现了此错误: ImportError: DLL load failed: %1 is not a valid Win32 application.

我们不知道具体问题是什么,也没有技能和知识来追溯这种问题的根源。

背景: 据我们理解,tesseract 是一个 32 位应用程序。我们正在运行 Windows 7,这是一个 64 位操作系统,使用 64 位 Python。其他人似乎也在这些条件下运行 tesseract,但这并不理想,可能会导致此问题。

堆栈跟踪 这是 PyCharm 中的错误跟踪。如您所见,它没有指定出问题的文件,而是说找不到看起来像是字符串格式参数的内容:%1

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.3\helpers\pydev\pydevd.py", line 1481, in 
    debugger.run(setup['file'], None, None)
  File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.3\helpers\pydev\pydevd.py", line 1124, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
  File "C:/Dropbox/COC/automate/coc_automate/python/__init__.py", line 7, in 
    import tesseract
  File "C:\Python27\lib\site-packages\tesseract.py", line 28, in 
    _tesseract = swig_import_helper()
  File "C:\Python27\lib\site-packages\tesseract.py", line 22, in swig_import_helper
    _mod = imp.load_module('_tesseract', fp, pathname, description)
ImportError: DLL load failed: %1 is not a valid Win32 application.

依赖关系检查器 针对看似有问题的文件 _tesseract.pyd 运行依赖关系检查器,发现了一些似乎很奇怪的东西:

它找不到 Python27.dll。

尽管我们已经成功地使用了 Python 很长时间了。

我们验证了系统中的 Python.dll 位于 C:\Windows\System32。

文件 MSVCR90.DLL 是错误的 CPU 版本。

它没有在 C:\Windows\System32 等“预期”的区域中找到,而是在已安装的利基图形库的程序文件目录中找到:c:\program files\graphicsmagick-1.3.18-q8\MSVCR90.DLL。两个安装之间是否存在相互混淆的问题?

PYTHON27.DLL Error opening file.            The system cannot find the file specified (2).
API-MS-WIN-CORE-COM-L1-1-0.DLL              The system cannot find the file specified (2).   
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL      The system cannot find the file specified (2).
API-MS-WIN-CORE-WINRT-L1-1-0.DLL            The system cannot find the file specified (2).
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL   The system cannot find the file specified (2).
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL     The system cannot find the file specified (2).
API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL        The system cannot find the file specified (2).
DCOMP.DLL                                   The system cannot find the file specified (2).
GPSVC.DLL                                   The system cannot find the file specified (2).
IESHIMS.DLL                                 The system cannot find the file specified (2).
...
c:\program files\graphicsmagick-1.3.18-q8\MSVCR90.DLL (Seems to be the wrong CPU version)

错误:至少一个必需的隐式或转发依赖项未找到。 错误:至少一个模块存在未解析的导入,因为隐式依赖模块中缺少导出函数。 错误:找到了不同 CPU 类型的模块。 警告:至少一个延迟加载依赖模块未找到。 警告:至少一个模块存在未解析的导入,因为延迟加载的依赖模块中缺少导出函数。

2、解决方案

MSVCR90.DLL 是 Visual C++ 2008 运行时的一部分。看来您需要在此处下载并安装运行时:www.microsoft.com/en-us/downl…

顺便说一下,在 python-tesseract 页面上说:

VS2008 编译的 Windows 版本现已可用!

似乎有人选择将应用程序编译为需要使用运行时 msvc++ 2008 运行时,而不是静态链接运行时库。您可能希望提出请求要求他们更改它,因为在任何要运行 Python 脚本的工作站上使用该 Python 模块都会添加额外的要求。