我执行了pytesseract的安装来从图像中提取文本,但是我的代码有一个我无法解决的问题,我已经查看了几个站点寻找错误的来源,但我仍然有问题……在错误消息中,它说没有安装tesseract,或者在路径中没有安装,但是我检查了与错误消息相同的目录,并且文件就在那里!
业务系统:
Linux 20.3肉桂
Python: 3.9
代码:
import cv2
import pytesseract
img = cv2.imread("./Desktop/screenshot.png")
text = pytesseract.image_to_string(img)
print(text)错误:
/usr/bin/python3.9 /home/alex/PycharmProjects/Kbot/main.py
Traceback (most recent call last):
File "/home/alex/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 255, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/alex/PycharmProjects/Kbot/main.py", line 7, in <module>
text = pytesseract.image_to_string(img)
File "/home/alex/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 409, in image_to_string
return {
File "/home/alex/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 412, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "/home/alex/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 287, in run_and_get_output
run_tesseract(**kwargs)
File "/home/alex/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site-packages/pytesseract/pytesseract.py", line 259, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
Process finished with exit code 1发布于 2022-06-23 04:17:47
你可能检查过那里有一个文件"/home/alex/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site-packages/pytesseract/pytesseract.py“,但是.pytesseract.py只是一个围绕您需要安装的tesseract引擎的包装器,以便pytesseract能够使用它。
使用安装tesseract
或在命令行中使用
$ sudo apt install tesseract-ocr -y
https://stackoverflow.com/questions/72720820
复制相似问题