gpt4 book ai didi

python - pytesseract OCR python 错误-示例代码

转载 作者:可可西里 更新时间:2023-11-01 09:28:20 25 4
gpt4 key购买 nike

您好,我试着学习如何使用 pytesseract(https://pypi.python.org/pypi/pytesseract),所以我运行示例代码:

try:
import Image
except ImportError:
from PIL import Image
import pytesseract
im=Image.open('test.png')
print(pytesseract.image_to_string(im))

但是我有错误:

Traceback (most recent call last):
File "C:/Users/K/PycharmProjects/untitled/zad1.py", line 7, in <module>
print(pytesseract.image_to_string(im))
File "C:\Users\K\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pytesseract-0.1.6-py3.5.egg\pytesseract\pytesseract.py", line 161, in image_to_string
File "C:\Users\K\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pytesseract-0.1.6-py3.5.egg\pytesseract\pytesseract.py", line 94, in run_tesseract
File "C:\Users\K\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\K\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

我的python版本是3.5,pytesseract版本是0.1.6。我在 Windows 7 上工作。

最佳答案

我的 Ubuntu 也遇到了这个问题。感谢@Newbie,我在安装tesseract后解决了它。

sudo apt-get install tesseract-ocr
sudo apt-get install tesseract-ocr-chi-sim

好像是

sudo pip install pytesseract

只安装 python 接口(interface)而不是 tesseract 本身

以下是我的错误信息:

OSError                                   Traceback (most recent call last)
<ipython-input-4-aaddc46c52ee> in <module>()
----> 1 pytesseract.image_to_string(Image.open('./static/files/captcha'))

/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.pyc in image_to_string(image, lang, boxes, config)
159 lang=lang,
160 boxes=boxes,
--> 161 config=config)
162 if status:
163 errors = get_errors(error_string)

/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.pyc in run_tesseract(input_filename, output_filename_base, lang, boxes, config)
92
93 proc = subprocess.Popen(command,
---> 94 stderr=subprocess.PIPE)
95 return (proc.wait(), proc.stderr.read())
96

/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
708 p2cread, p2cwrite,
709 c2pread, c2pwrite,
--> 710 errread, errwrite)
711 except Exception:
712 # Preserve original exception in case os.close raises.

/usr/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
1333 raise
1334 child_exception = pickle.loads(data)
-> 1335 raise child_exception
1336
1337

OSError: [Errno 2] No such file or directory

关于python - pytesseract OCR python 错误-示例代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35420427/

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