Tesseract not found error

Hi, I am using opencv and tesseract .the code is working fine in local machine
But when I deploy the app in streamlit cloud it displays the below error

pytesseract.pytesseract.TesseractNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)File "/mount/src/ocrapp/app.py", line 100, in <module>
    text = text_extract(img, option1, slang, dlang)File "/mount/src/ocrapp/app.py", line 78, in text_extract
    text = pytesseract.image_to_string(gray, lang=lan)File "/home/adminuser/venv/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 423, in image_to_string
    return {File "/home/adminuser/venv/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 426, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),File "/home/adminuser/venv/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 288, in run_and_get_output
    run_tesseract(**kwargs)File "/home/adminuser/venv/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 260, in run_tesseract
    raise TesseractNotFoundError()

and for some images it is also showing the below error
cv2.error: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)File "/mount/src/ocrapp/app.py", line 100, in <module>
    text = text_extract(img, option1, slang, dlang)File "/mount/src/ocrapp/app.py", line 77, in text_extract
    gray = preprocess(img)File "/mount/src/ocrapp/app.py", line 71, in preprocess
    gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)

link for app: https://3hkf8stzrzvlmwrey5ephp.streamlit.app/
github repo: GitHub - asritha205/ocrapp

please help me resolve this

1 Like

Hi there,

Thanks for sharing this question!

In your code (line 15), you are passing the path to Tesseract as your local file system path for a deployed app.

pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'

You would need a path that your code can access when deployed to Streamlit Community Cloud like uploading the file to GitHub.

You can also browse through similar questions on our forum that might have the answer to most of the questions on this topic.

1 Like

You would need a path that your code can access when deployed to Streamlit Community Cloud like uploading the file to GitHub.

Can you please explain this .Do I need to add tesseract file to the githubrepo?And use that path

I found this previous solution from another post provided by @snehankekre that you might want to give a try.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.