image_to_string não funciona no Mac
-
21-12-2019 - |
Pergunta
Estou tentando seguir este exemplo de pytesser (link) em um Mac Maverick.
>>> from pytesser import *
>>> im = Image.open('phototest.tif')
>>> text = image_to_string(im)
Mas, na última linha recebo esta mensagem de erro:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pytesser.py", line 31, in image_to_string
call_tesseract(scratch_image_name, scratch_text_name_root)
File "pytesser.py", line 21, in call_tesseract
proc = subprocess.Popen(args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Mas não entendo o que devo fazer.O arquivo phototest está na mesma pasta em que estou executando o script.Como consertar isto?
ATUALIZAR:
Quando eu tento
brew install tesseract
Eu recebo este erro:
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
Error: You must `brew link libtiff libpng jpeg' before tesseract can be installed
Solução
Na verdade, tive o mesmo erro que você, e foi assim que encontrei esta postagem.Eu também tenho a solução para o meu problema, porque você me deu!
Eu estava vendo:
ryan.davis$ python tesseract.py
Traceback (most recent call last):
File "tesseract.py", line 52, in <module>
print (image_to_string(big))
File "/usr/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
config=config)
File "/usr/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Quer saber o que tive que fazer para consertar isso?Exatamente o que você tentou: brew install tesseract
Eu instalei a biblioteca python tesseract, mas não a instalei no nível do sistema.Então isso resolve meu problema.E o seu?
Acho que você pode ter se distraído com isso:
Aviso:Parece que você tem MacPorts ou Fink instalados.Software instalado com outros gerenciadores de pacotes causa problemas conhecidos para Homebrew.Se uma fórmula não for compilada, desinstale MacPorts/Fink e tente outra vez.
E não percebi que sua resposta já foi fornecida na resposta do brew:
Você deve preparar o link Libtiff libpng jpeg antes que o TESSERACT possa ser instalado.
Então faz:
brew link libtiff
brew link libpng
brew link jpeg
Então:
brew install tesseract
Finalmente:
:)