billviking / pytesser

Automatically exported from code.google.com/p/pytesser
Other
0 stars 0 forks source link

pytesser does not find tesseract.exe from other working dir #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Import pytesser into a script that's on a different path
2. Try and run pytesser.image_to_string()
3.

What is the expected output? What do you see instead?
This is how it crashes:
Traceback (most recent call last):
  File "z:\scripts\bruker\grabMicroStar.py", line 107, in <module>
    text = pytesser.image_to_string(snap).strip()
  File "z:\scripts\bruker\pytesser\pytesser.py", line 41, in image_to_string
    call_tesseract(scratch_image_name, scratch_text_name_root)
  File "z:\scripts\bruker\pytesser\pytesser.py", line 31, in call_tesseract
    proc = subprocess.Popen(args)
  File "c:\programs\Python26\lib\subprocess.py", line 633, in __init__
    errread, errwrite)
  File "c:\programs\Python26\lib\subprocess.py", line 842, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

What version of the product are you using? On what operating system?
v0.0.1

Please provide any additional information below.
The problem is that it doesn't know where to find the tesseract.exe executable 
if current working directory is not the same as that of the script (likely).  
The fix is:  in pytesser.py, add the following lines after tesseract_exe_name, 
which figure out the path:

#=========================================
if 'pytesser' in sys.modules:
   tesseract_exe_path = sys.modules['pytesser'].__path__[0]
else:
   tesseract_exe_path = os.getcwd()
tesseract_exe_name = os.path.join(tesseract_exe_path,tesseract_exe_name)
#=========================================

Original issue reported on code.google.com by loret...@gmail.com on 15 Jun 2010 at 12:42

GoogleCodeExporter commented 8 years ago
in this code the line :
tesseract_exe_path = sys.modules['pytesser'].__path__[0]
return:
Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    sys.modules['pytesser'].__path__[0]
AttributeError: 'module' object has no attribute '__path__'

Original comment by 66h...@gmail.com on 21 Dec 2012 at 8:18