0

When running this script and trying to paste it, it doesn't work.

import pytesseract
import pyperclip
import PIL.Image

# Open the image file
image = PIL.Image.open('generate_word_picture.png')

# Extract the text from the image using pytesseract
text = pytesseract.image_to_string(image)

# Copy the text to the clipboard
pyperclip.copy(text)

This is the image: Image

I have these installed:

-pip install pytesseract

-pip install pyperclip

-https://github.com/UB-Mannheim/tesseract/wiki

Syrex
  • 1
  • 3
  • Could it maybe be that the image is too difficult? – Syrex Dec 22 '22 at 03:11
  • What do you mean by 'it doesn't work'? Does the code fail, or does it incorrectly transcribe the text? – Gamma032 Dec 22 '22 at 03:22
  • Like when I try pasting my keyboard it just pastes whatever I copied before but it seems like the script doesn't copy anything into my clipboard. – Syrex Dec 22 '22 at 03:27
  • What happens if you add `print(text)`? Is there a string? – Gamma032 Dec 22 '22 at 03:28
  • Nope the script just instantly closes itself – Syrex Dec 22 '22 at 03:34
  • Have you installed pytesseract on your PC? Because you will need the tesseract.exe to run + your pytesseract library on the script. – Sin Han Jinn Dec 22 '22 at 03:36
  • Yeah as I said I have installed these: -pip install pytesseract ; -pip install pyperclip ; -https://github.com/UB-Mannheim/tesseract/wiki – Syrex Dec 22 '22 at 03:40
  • Can you add print(text) right above the pyperclip.copy(text) then see if it is able to extract any text from the image? There could be two issues here. The first issue could be with the pytesseract the second could be with the pyperclip. – thesonyman101 Dec 22 '22 at 03:47
  • If you see text printed then the issue is with the pyperclip. Doing this kind of stuff is the building blocks of being able to debug your own code. So it will be good for you to learn about this. – thesonyman101 Dec 22 '22 at 03:48
  • One other thing when you said "Nope the script just instantly closes itself" Could you be just clicking the python file? If so the output window isn't going to stick around. Try running the python file using cmd. – thesonyman101 Dec 22 '22 at 03:51
  • I recommend that you read this. https://realpython.com/run-python-scripts/#:~:text=To%20run%20Python%20scripts%20with,see%20the%20phrase%20Hello%20World! – thesonyman101 Dec 22 '22 at 03:52
  • One other thing. As the others have said. pip install pytesseract only installs the tesseract wrapper. It would be best if you read this https://pythonforundergradengineers.com/how-to-install-pytesseract.html for info on installing the executable and adding it to the path. – thesonyman101 Dec 22 '22 at 03:58
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 22 '22 at 10:16

0 Answers0