gpt4 book ai didi

python - 如何修复 "PATH"问题?

转载 作者:行者123 更新时间:2023-12-01 00:51:51 35 4
gpt4 key购买 nike

我创建了一个将图像打印为文本的程序。

环境变量

  • 变量名称:pytesseract
  • 变量值:pytesseract.pytesseract.tesseract_cmd=r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'

//代码

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

关于python - 如何修复 "PATH"问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56512723/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com