本文介绍了如何将 pytesseract 部署到 Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Python 应用程序,它在我的机器上通过 Localhost 写得很好.

I have a Python app which words great via Localhost on my machine.

我正在尝试将其部署到 Heroku.然而,这似乎不可能实现(我现在已经花了大约 30 个小时尝试).

I am trying to deploy it to Heroku. However it does not seem possible to accomplish this (I have spent approx 30 hours trying now).

问题是 Tesseract OCR.我正在使用 pytesseract 包装器,我的代码利用了它.但是,无论我尝试什么,在将pytesseract上传到Heroku时似乎都无法使用它.

The problem is Tesseract OCR. I am using the pytesseract wrapper, and my code utilises this. However, no matter what I try, it does not seem to be possible to use pytesseract when it is uploaded to Heroku.

有人可以建议如何通过 pytesseract 将 Hello World Tesseract OCR Python 应用程序部署到 Heroku,或者如果 Heroku 无法做到这一点,请提出 Heroku 的替代方案吗?

Could anyone either suggest how to go about deploying a Hello World Tesseract OCR Python app via pytesseract to Heroku, or if Heroku is not capable of this, suggest an alternative to Heroku?

推荐答案

对于希望在 heroku 上部署 pytesseract 的其他人,这里是步骤:

For anyone else looking to deploy pytesseract on heroku, here are the steps:

  • 将 apt buildpack 添加到 heroku

  • Add apt buildpack to heroku

heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt

  • 在与您的应用程序相同的目录中创建一个名为 Aptfile 的文件,并将这些行添加到它(英文)

  • Create a file named Aptfile in the same directory as your app and these lines to it (for english)

    tesseract-ocr
    tesseract-ocr-eng
    

  • 将heroku配置变量TESSDATA_PREFIX设置为tessdata文件夹的路径(它是/app/.apt/usr/share/tesseract-ocr/4.00/tessdata 对我来说)可以通过使用 heroku run bash 运行 heroku shell 并在 shell 中运行此命令来找到

  • Set heroku config variable TESSDATA_PREFIX to the path of tessdata folder (it was /app/.apt/usr/share/tesseract-ocr/4.00/tessdata for me) which can be found out by running heroku shell using heroku run bash and run this command in the shell

    find -iname tessdata
    

  • 使用

  • Set the config variable using

    heroku config:set TESSDATA_PREFIX=/app/.apt/usr/share/tesseract-ocr/4.00/tessdata
    

    用你从上一个命令得到的路径替换路径

    replace the path with the path you got from the previous command

    Tesseract 应在您构建时安装在 heroku 应用程序中.确保您的 requirements.txt 文件中有 pytesseract.现在你应该可以在 heroku 上导入和使用 pytesseract

    Tesseract should be installed in the heroku app when you build it. Make sure you have pytesseract in your requirements.txt file. Now you should be able import and use pytesseract on heroku

    这篇关于如何将 pytesseract 部署到 Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 07-23 11:06
    查看更多