在 Windows Server 2016 上安装 OCRmyPDF - 找不到 liblept.dll。编辑路径安全吗?

Installing OCRmyPDF on Windows Server 2016 - Can't find liblept.dll. Is editing Path safe?

我正在尝试使用 Python 37-32 在我公司客户的 Windows Server 2016 Build 14393 计算机上导入 ocrmypdf。当我在 Jupyter Notebook 中导入库时,无法使用 ctypes.utility.find_library().

找到 leptonica

Ocrmypdf 是 Linux 开发的 Python 3 软件包。根据文档 (https://ocrmypdf.readthedocs.io/en/latest/introduction.html),它不支持 Windows。建议的解决方法是 docker 容器和 Linux 的 Windows 子系统。

我宁愿不使用 docker 容器,因为我和我的同事都没有使用它的经验。我无法使用 wsl,因为它不适用于我构建的 Windows Server 2016(请参阅故障排除小节:https://docs.microsoft.com/en-us/windows/wsl/install-on-server

此讨论 (find_library() in ctypes) 声明您可以通过将环境 Path 变量编辑为包含它的文件夹,将 ctypes.utility.find_library 指向所需的库文件。方便的是,Tesseract OCR 的 windows 下载包括 liblept。编辑 Path 变量以指向该文件夹会是一件危险的事情吗?

编辑:我尝试在笔记本电脑的环境路径中添加到 Tesseract-OCR 文件夹的路径并重新启动 Anaconda 等。ocrmypdf 仍然给出相同的错误。 仔细阅读该讨论提出 find_library 在 Windows 上的操作不同这一点。阅读文档 (https://docs.python.org/2.5/lib/ctypes-finding-shared-libraries.html) 指出 "On Windows, find_library searches along the system search path, and returns the full pathname, but since there is no predefined naming scheme a call like find_library("c") 将失败并且 return None."这是否意味着我必须硬编码名称才能找到库?

此问题已被复制,尽管是在不同的机器上,此处:https://github.com/jbarlow83/OCRmyPDF/issues/341。您可以在 Windows 机器上通过 运行 以下代码重现该问题。

!pip install ocrmypdf
import ocrmypdf

以上代码的预期结果是以可用的形式成功导入ocrmypdf。 上面代码的结果是:

OSError                                   Traceback (most recent call last)
<ipython-input-2-a81f3474d7ad> in <module>
----> 1 import ocrmypdf

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ocrmypdf\__init__.py in <module>
     16 # along with OCRmyPDF.  If not, see <http://www.gnu.org/licenses/>.
     17 
---> 18 from . import helpers, hocrtransform, leptonica, pdfa, pdfinfo
     19 from ._version import PROGRAM_NAME, __version__
     20 from .api import Verbosity, configure_logging, ocr

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ocrmypdf\leptonica.py in <module>
     40 logger = logging.getLogger(__name__)
     41 
---> 42 lept = ffi.dlopen(find_library('lept'))
     43 lept.setMsgSeverity(lept.L_SEVERITY_WARNING)
     44 

OSError: cannot load library '<None>': error 0x57

我已经能够通过更新路径使它正常工作 Windows10,它工作正常。我使用 msys2 来安装它,因此是路径名。更新到您的 liblept-5.dll 所在的位置。

if os.name == 'nt':
    os.environ['PATH'] = os.environ.get("PATH", "") + ';C:\msys64\mingw64\bin'