h / pytesseract

Python-tesseract is an optical character recognition (OCR) tool for python
https://github.com/h/pytesseract
GNU General Public License v3.0
85 stars 2 forks source link

FileNotFoundError: [Errno 2] No such file or directory: tess_[something].txt #6

Open Markus-N opened 3 weeks ago

Markus-N commented 3 weeks ago

Today, my program using pytesseract stopped working. I did some software updates yesterday, which updated python from 3.12.5-1 to 3.12.7-1. Neither tesseract nor pytesseract were part of the update. OS is Arch Linux.

This is the stack trace I get (beginning at the pytesseract call) plus my config:

    config: str = '--oem 3 --psm 7'
    detected_text: str = pytesseract.image_to_string(image_grayscale, lang='eng', config=config)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pytesseract/pytesseract.py", line 486, in image_to_string
    return {
           ^
  File "/usr/lib/python3.12/site-packages/pytesseract/pytesseract.py", line 489, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
                           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pytesseract/pytesseract.py", line 353, in run_and_get_output
    return _read_output(
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pytesseract/pytesseract.py", line 288, in _read_output
    with open(filename, 'rb') as output_file:
         ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/markus/temp/tess_b5knytys.txt'

I have the environment variable TEMP set to /home/markus/temp. I took a look at pytesseract.py, and it could be a problem with NamedTemporaryFile. Not 100% sure if the update is the culprit (I'm still relatively new to Python), but if so, maybe pytesseract needs some adaptations to changes in the the new Python version.

Unfortunately, downgrading software is highly discouraged (and a bit cumbersome) on Arch Linux.