@@ -994,6 +994,92 @@ def install_ocr():
994994def image_search (step_data_set ):
995995 install_ocr ()
996996 sModuleInfo = inspect .currentframe ().f_code .co_name + " : " + MODULE_NAME
997+ try :
998+ # steps to install the pytesseract module
999+ pip_command = ['pip' , 'list' ]
1000+ pytesseract_search_command = ['findstr' , 'pytesseract' ]
1001+
1002+ pip_process = subprocess .Popen (pip_command , stdout = subprocess .PIPE )
1003+ search_process = subprocess .Popen (pytesseract_search_command , stdin = pip_process .stdout , stdout = subprocess .PIPE ,
1004+ text = True )
1005+
1006+ is_pytesseract , _ = search_process .communicate ()
1007+
1008+ if is_pytesseract :
1009+ CommonUtil .ExecLog (
1010+ sModuleInfo ,
1011+ "Pytesseractt is already installed" ,
1012+ 5 ,
1013+ )
1014+ else :
1015+ CommonUtil .ExecLog (
1016+ sModuleInfo ,
1017+ "Installing Pytesseract" ,
1018+ 5 ,
1019+ )
1020+ os .system ('echo y | pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pytesseract' )
1021+ except :
1022+ CommonUtil .ExecLog (
1023+ sModuleInfo ,
1024+ "Could not install the Pytesseract module" ,
1025+ 3 ,
1026+ )
1027+
1028+ try :
1029+ # steps to install pytesseract executable file
1030+ reg_query_cmd = ['reg' , 'query' , r'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' , '/s' ]
1031+ findstr_cmd = ['findstr' , '/B' , '.*DisplayName' ]
1032+ tesseract_cmd = ['findstr' , 'Tesseract-OCR' ]
1033+
1034+ reg_query_process = subprocess .Popen (reg_query_cmd , stdout = subprocess .PIPE )
1035+ findstr_process = subprocess .Popen (findstr_cmd , stdin = reg_query_process .stdout , stdout = subprocess .PIPE )
1036+ tesseract_process = subprocess .Popen (tesseract_cmd , stdin = findstr_process .stdout , stdout = subprocess .PIPE ,
1037+ text = True )
1038+
1039+ is_pytesseract_exe , _ = tesseract_process .communicate ()
1040+
1041+ if is_pytesseract_exe :
1042+ CommonUtil .ExecLog (
1043+ sModuleInfo ,
1044+ "Pytesseract executable file is alreday installed" ,
1045+ 5 ,
1046+ )
1047+ else :
1048+ CommonUtil .ExecLog (
1049+ sModuleInfo ,
1050+ "Starting installation of Pytesseract executable file" ,
1051+ 5 ,
1052+ )
1053+ install_process = subprocess .Popen (['winget' , 'install' , 'Tesseract-OCR - open source OCR engine' ],
1054+ text = True )
1055+ stdout , stderr = install_process .communicate ()
1056+ if stdout is not None :
1057+ CommonUtil .ExecLog (sModuleInfo , f"The standard output for winget install Tesseract-OCR { stdout } " , 5 )
1058+ if stderr is not None :
1059+ CommonUtil .ExecLog (
1060+ sModuleInfo ,
1061+ f"The standard error for winget install Tesseract-OCR { stderr } " ,
1062+ 5 ,
1063+ )
1064+ else :
1065+ CommonUtil .ExecLog (sModuleInfo , f"Tesseract installation is complete!" , 5 )
1066+
1067+ CommonUtil .ExecLog (
1068+ sModuleInfo ,
1069+ "Setting up the environment variable for Tesseract OCR" ,
1070+ 5 ,
1071+ )
1072+
1073+ # Todo: No need to add this in PATH
1074+ ocr_path = r"C:\Program Files\Tesseract-OCR"
1075+ os .environ ['PATH' ] += ';' + ocr_path
1076+ except :
1077+ CommonUtil .ExecLog (
1078+ sModuleInfo ,
1079+ "Could not install the Pytesseract executable file" ,
1080+ 3 ,
1081+ )
1082+
9971083 try :
9981084 file_name = ""
9991085 resolution = ""
0 commit comments