[英]How to fix "PATH" issue?
我创建了一个将图像打印为文本的程序。
环境变量
//代码
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd= r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
image1 = Image.open("C:\python\program\image.png")
print(pytesseract.image_to_string(image1))
错误:
Traceback (most recent call last):
File "C:/python/program/Image_OCR.py", line 13, in <module>
print(pytesseract.image_to_string(image1))
File "C:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 338, in image_to_string
}[output_type]()
File "C:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 337, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 246, in run_and_get_output
run_tesseract(**kwargs)
File "C:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 222, in run_tesseract
raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file \\Program Files (x86)\\Tesseract-OCR\\tessdata/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
实际结果:将图像打印为文本。
我有同样的问题。 我正在使用 Ubuntu。 我评论了以下行pytesseract.pytesseract.tesseract_cmd = '/app/.apt/usr/bin/tesseract'
它对我有用。
尝试删除/注释该行pytesseract.pytesseract.tesseract_cmd= r'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.