Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我对Ubuntu上的pytesseract有问题_Python 3.x_Tesseract_Telegram Bot - Fatal编程技术网

Python 3.x 我对Ubuntu上的pytesseract有问题

Python 3.x 我对Ubuntu上的pytesseract有问题,python-3.x,tesseract,telegram-bot,Python 3.x,Tesseract,Telegram Bot,我正在尝试制作一个电报机器人,其功能之一是从图像中识别文本,在Windows上一切正常,但一旦切换到Linux,我立即遇到同样的异常,起初我认为我错误地指定了路径pytesseract.pytesseract.tesseract\u cmd(因为我访问过的网站写的都是这个,但是经过仔细检查,我没有发现任何错误) 这是我的密码: 来自telebot导入类型的 从谷歌搜索导入搜索 从PIL导入图像 导入pytesseract 进口cv2 导入操作系统 将numpy作为np导入 进口遥控机器人 导入配

我正在尝试制作一个电报机器人,其功能之一是从图像中识别文本,在Windows上一切正常,但一旦切换到Linux,我立即遇到同样的异常,起初我认为我错误地指定了路径
pytesseract.pytesseract.tesseract\u cmd
(因为我访问过的网站写的都是这个,但是经过仔细检查,我没有发现任何错误) 这是我的密码:

来自telebot导入类型的

从谷歌搜索导入搜索
从PIL导入图像
导入pytesseract
进口cv2
导入操作系统
将numpy作为np导入
进口遥控机器人
导入配置
bot=telebot.telebot(config.token)
@bot.message\u处理程序(内容类型=[“照片”])
def应答至照片(信息):
状态=[“创建者”、“管理员”、“成员”]
user\u status=str(bot.get\u chat\u成员(chat\u id='chat id',user\u id=message.from\u user.id).状态)
如果用户状态为“状态”:
pytesseract.pytesseract.tesseract_cmd=r'/home/shalor1k/.local/bin/pytesseract'
file\u info=bot.get\u文件(message.photo[len(message.photo)-1]。文件\u id)
下载的\u文件=bot.download\u文件(file\u info.file\u路径)
src=r'C:\bot\photo'+message.photo[1]。文件\u id
打开(src,'wb')作为新的\u文件:
新建\u文件。写入(下载的\u文件)
bot.reply_to(消息“正在处理您的照片”)
image=src
preprocess=“thresh”
image=cv2.imread(图像)
灰色=cv2.CVT颜色(图像,cv2.COLOR\u BGR2GRAY)
如果预处理==“tresh”:
灰色=cv2。阈值(灰色,0,255,
cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
elif预处理==“模糊”:
灰色=cv2.中值.模糊(灰色,3)
filename=“{}.png”。格式(os.getpid())
cv2.imwrite(文件名,灰色)
text=pytesseract.image\u to\u字符串(image.open(文件名),lang='rus')
删除(文件名)
删除操作系统(src)
例外情况的案文:

File "main_bot_for_server.py", line 67, in answer_to_photo
    text = pytesseract.image_to_string(Image.open(filename), lang = 'rus')
  File "/home/shalor1k/.local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 370, in image_to_string
    return {
  File "/home/shalor1k/.local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 373, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "/home/shalor1k/.local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 282, in run_and_get_output
    run_tesseract(**kwargs)
  File "/home/shalor1k/.local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 258, in run_tesseract
    raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (2, 'Usage: pytesseract [-l lang] input_file')
文件“main\u bot\u for\u server.py”,第67行,在对照片的回答中
text=pytesseract.image\u to\u字符串(image.open(文件名),lang='rus')
文件“/home/shalor1k/.local/lib/python3.8/site packages/pytesseract/pytesseract.py”,第370行,在图像字符串中
返回{
文件“/home/shalor1k/.local/lib/python3.8/site packages/pytesseract/pytesseract.py”,第373行,在
Output.STRING:lambda:run_和_get_Output(*args),
文件“/home/shalor1k/.local/lib/python3.8/site packages/pytesseract/pytesseract.py”,第282行,在运行和获取输出中
运行_tesseract(**kwargs)
文件“/home/shalor1k/.local/lib/python3.8/site packages/pytesseract/pytesseract.py”,第258行,在run_tesseract中
raise TESSERATERROR(proc.returncode,get_errors(error_string))
pytesseract.pytesseract.tesseracter错误:(2,'用法:pytesseract[-l lang]输入文件')

第一个问题是未安装自身的二进制文件。 第二个问题是没有安装所需的语言包