'Failing to deploy flask tesseract app to heroku

I wanted to deploy my tesseract app to heroku but it is always 'unable to locate package tesseract-ocr' and is unable to deploy it.

I was following this tutorial and this

My steps:

  1. Write pytesseract.pytesseract.tesseract_cmd = ‘/app/.apt/usr/bin/tesseract’ to my app-code
  2. Get requirements.txt, procfile and Aptfile including tesseract-ocr tesseract-ocr-eng
  3. Add Buildpack https://github.com/heroku/heroku-buildpack-apt (I added it directly at settings), I also tried this buildpack: https://github.com/matteotiziano/heroku-buildpack-tesseract
  4. Add Tesseract config file: TESSDATA_PREFIX = ./.apt/usr/share/tesseract-ocr/4.00/tessdata (here should be the correct path of tesseract but the 'find -iname tessdata' does not work for me. I'm using the run console directly on the heroku website and I tried it also on my computer with heroku run bash -a myappname and there were also nothing displayed.) I added 'TESSDATA_PREFIX' under 'Key' and './.apt/usr/share/tesseract-ocr/4.00/tessdata' under 'Value'. Additionally tried it with: /app/.apt/usr/share/tesseract-ocr/4.00/tessdata and /app/.apt/usr/share/tesseract-ocr/tessdata)
  5. Then I'm deploying it again (I have it already deployed before I'm adding the Buildpack etc.)

This is the Error I get:

E: Unable to locate package tesseract-ocr
 !     Push rejected, failed to compile Apt app.
 !     Push failed

Thank you very much for your help!

Further information: my app does work locally on postman, so I don't think it's a coding issue.



Solution 1:[1]

Like you, I spent many hours over the last three days scouring the internet for clues to this mystifying puzzle. It was discovered that the problem was due to a bug with Heroku's buildpack relating to different newlines used by different operating systems - Windows uses CRLF while Linux uses LF (I am on Windows using WSL, I assume this issue also applies to you on Windows). Whenever I used a single package, the build would work, but whenever I added additional packages Heroku would tell me it was unable to locate them. If you are on Windows, you would need a way to ensure you have the correct newline character to prevent this from happening (I used vim in WSL).

For anyone using WSL as I am, there is yet another issue where git will convert any newline characters to CRLF, so even though I edited using an LF newline, I ended up with the same error that Heroku could not locate the desired package. As suggested, use git config --global core.autocrlf false to disable this, then ensure your file uses only LF newlines, then push.

I was mindblown that these issues have persisted for this long and I was not able to find a single thread detailing this fix, but hopefully this works for you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 IIInitiationnn