I’m new to python and coding, and I am writing a piece of code to take a look at a ruler’s numbers using pytesseract. Here’s a short snippet of code including everything relevant to my issue:
import pytesseract as tess
*#Pytesseract is highlighted as something that hasn't properly been imported*
raw_ruler = print(tess.image_to_string(gray_test_image)) #Assume gray_test_image is a processed photo
lines = raw_ruler.strip().split('n')
numbers = [int(line) for line in lines]
first_number = numbers[0]
inch_range = last_number - first_number
image_width_pixels = 4240
ppi_width = image_width_pixels/inch_range
pixel_range = ppi_width * inch_range
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytesseract/pytesseract.py:255, in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
254 try:
--> 255 proc = subprocess.Popen(cmd_args, **subprocess_args())
256 except OSError as e:
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py:1026, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)
1023 self.stderr = io.TextIOWrapper(self.stderr,
1024 encoding=encoding, errors=errors)
-> 1026 self._execute_child(args, executable, preexec_fn, close_fds,
1027 pass_fds, cwd, env,
1028 startupinfo, creationflags, shell,
1029 p2cread, p2cwrite,
1030 c2pread, c2pwrite,
1031 errread, errwrite,
1032 restore_signals,
1033 gid, gids, uid, umask,
1034 start_new_session, process_group)
1035 except:
1036 # Cleanup if the child failed starting.
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py:1955, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session, process_group)
1954 if err_filename is not None:
-> 1955 raise child_exception_type(errno_num, err_msg, err_filename)
...
--> 260 raise TesseractNotFoundError()
262 with timeout_manager(proc, timeout) as error_string:
263 if proc.returncode:
TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
I have verified that pytesseract is installed via homebrew:
$ brew reinstall tesseract
==> Downloading https://ghcr.io/v2/homebrew/core/tesseract/manifests/5.4.1
Already downloaded: /Users/4494177/Library/Caches/Homebrew/downloads/90a14ece96dee96d869e7eb9be23351b2da94395dbf347f386a130f23cfe1ac8--tesseract-5.4.1.bottle_manifest.json
==> Fetching tesseract
==> Downloading https://ghcr.io/v2/homebrew/core/tesseract/blobs/sha256:41f0427b
Already downloaded: /Users/4494177/Library/Caches/Homebrew/downloads/253884c99fb6de00e50b5d6e48e23e3545556f09d9e2f05eea46a090164375c8--tesseract--5.4.1.arm64_sonoma.bottle.tar.gz
==> Reinstalling tesseract
==> Pouring tesseract--5.4.1.arm64_sonoma.bottle.tar.gz
==> Caveats
This formula contains only the "eng", "osd", and "snum" language data files.
If you need any other supported languages, run `brew install tesseract-lang`.
==> Summary
???? /opt/homebrew/Cellar/tesseract/5.4.1: 75 files, 33MB
==> Running `brew cleanup tesseract`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
I’ve been stuck with this issue for a while, and help would be greatly appreciated!
I’ve tried looking at the path, and have had trouble knowing exactly what that means, I’ve looked up how to verify it via command terminal, and sometimes I get positive results, other times nothing is outputted.
Quinten Neudorf Boosters is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.