问题
I have a Python app which words great via Localhost on my machine.
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).
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.
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?
回答1:
For anyone else looking to deploy pytesseract on heroku, here are the steps:
Add apt buildpack to heroku
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
Create a file named
Aptfile
in the same directory as your app and these lines to it (for english)tesseract-ocr tesseract-ocr-eng
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 usingheroku run bash
and run this command in the shellfind -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 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
回答2:
The Python buildpack likely doesn't have the tesseract binaries installed by default. Here’s a third-party buildpack that creates the appropriate environment. Follow the instructions there to make the binary available to your application.
来源:https://stackoverflow.com/questions/53363547/how-to-deploy-pytesseract-to-heroku