The error you encountered indicates that the Tesseract OCR executable is not installed or not found in your system's PATH. Here’s how to resolve it:
C:\\\\Program Files\\\\Tesseract-OCR\\\\tesseract.exe. Make sure this path is correct.This PC or Computer on your desktop or in File Explorer and select Properties.Advanced system settings.Environment Variables button.Path variable in the System variables section and select it. Click Edit.New and add the path to the Tesseract executable, e.g., C:\\\\Program Files\\\\Tesseract-OCR\\\\.OK to close all the windows.Here’s the updated Python script with the Tesseract path specified explicitly:
from PIL import Image
import pytesseract
# Specify the path to the Tesseract OCR executable
pytesseract.pytesseract.tesseract_cmd = r'C:\\\\Program Files\\\\Tesseract-OCR\\\\tesseract.exe'
def extract_text_from_image(image_path):
# Open the image file
img = Image.open(image_path)
# Use pytesseract to do OCR on the image
text = pytesseract.image_to_string(img)
return text
if __name__ == "__main__":
image_path = 'path_to_your_image.jpg' # Replace with your image path
extracted_text = extract_text_from_image(image_path)
print("Extracted Text:\\\\n", extracted_text)
Replace 'path_to_your_image.jpg' with the actual path to your image file.
By specifying the path explicitly in pytesseract.pytesseract.tesseract_cmd, you ensure that the script knows where to find the Tesseract executable, avoiding the need to modify the PATH environment variable. This should resolve the TesseractNotFoundError.