Skip to content

Instantly share code, notes, and snippets.

Last active January 7, 2023 11:02
What would you like to do?
import pytesseract
import sys
import argparse
import Image
except ImportError:
from PIL import Image
from subprocess import check_output
def resolve(path):
print("Resampling the Image")
check_output(['convert', path, '-resample', '600', path])
return pytesseract.image_to_string(
if __name__=="__main__":
argparser = argparse.ArgumentParser()
argparser.add_argument('path',help = 'Captcha file path')
args = argparser.parse_args()
path = args.path
print('Resolving Captcha')
captcha_text = resolve(path)
print('Extracted Text',captcha_text)
Copy link

I got below error.
Please help.

Resolving Captcha
Resampling the Image
Traceback (most recent call last):
File "C:\Users\yenag\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\", line 226, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "C:\Users\yenag\AppData\Local\Programs\Python\Python38-32\lib\", line 854, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\yenag\AppData\Local\Programs\Python\Python38-32\lib\", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 22, in
captcha_text = resolve(path)
File "", line 14, in resolve
return pytesseract.image_to_string(
File "C:\Users\yenag\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\", line 344, in image_to_string
return {
File "C:\Users\yenag\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\", line 347, in
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\yenag\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\", line 258, in run_and_get_output
File "C:\Users\yenag\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\", line 230, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

Copy link

sudo apt-get install tesseract-ocr

Copy link

Code works fine but doesn't extract the captcha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment