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:

  1. Install Tesseract OCR:
  2. Add Tesseract to your PATH:
  3. Specify the Tesseract path in the code: If you don't want to modify the PATH variable or if it still doesn't work, you can directly specify the path in your script.

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.