(2,'用法:pytesseract [-l lang] input_file')在Google Colab上

时间:2020-07-14 21:50:37

标签: python google-colaboratory python-tesseract

我正在尝试将Tesseract运行到Google Colab:

!sudo apt install tesseract-ocr
!pip install pytesseract

import pytesseract
import shutil
import os
import random
try:
 from PIL import Image
except ImportError:
 import Image

from google.colab import files
uploaded = files.upload()

extractedInformation = pytesseract.image_to_string(Image.open('aaa.png'))
print(extractedInformation)

我尝试在要上传的图片('aaa.png')上运行,但运行此错误:

TesseractError: (2, 'Usage: pytesseract [-l lang] input_file')

从几乎完全相同(仍未解决)的帖子中搜索,我尝试了以下代码,但仍无法正常工作:

pytesseract.pytesseract.tesseract_cmd = (
    r'/usr/local/bin/tesseract'
)

我尝试访问pytesseract文件夹,但它运行此错误:

enter image description here

PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/pytesseract/pytesseract.py'

1 个答案:

答案 0 :(得分:2)

使用以下方法解决:

pytesseract.pytesseract.tesseract_cmd = (
    r'/usr/bin/tesseract'
)