Python pytesseract-没有这样的文件或目录错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28741563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:40:44  来源:igfitidea点击:

pytesseract-no such file or directory error

pythonpython-2.7ubuntu-14.04

提问by chaitanya90

I am using Ubuntu 14.04. I have the following code:

我正在使用 Ubuntu 14.04。我有以下代码:

import Image
import pytesseract
im = Image.open('test.png')
print pytesseract.image_to_string(im)

but I keep getting the following error:

但我不断收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
    execfile(filename, namespace)
  File "/home/chaitanya/pythonapp/localcopy.py", line 4, in <module>
    print pytesseract.image_to_string(im)
  File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 142, in image_to_string
    config=config)
  File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 75, in run_tesseract
    stderr=subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Both the python program and the image are in the same location.What could be the problem??

python程序和图像都在同一个位置。可能是什么问题??

采纳答案by Padraic Cunningham

You need to install tesseract-ocr:

您需要安装tesseract-ocr

sudo apt-get install tesseract-ocr

回答by Shaz

If you're on windows and have PIP installed go to your project directory and run:

如果您使用的是 Windows 并安装了 PIP,请转到您的项目目录并运行:

pip install tesseract-ocr

pip install tesseract-ocr

回答by Thej Kiran

Based off of @padraic cunningham's answer which I tailored to my setting.

基于@padraic cunningham 的回答,我根据自己的设置量身定制。

If you are on Linux (ubuntu 16, should not matter) and have a conda installation:

如果您使用的是 Linux(ubuntu 16,应该无关紧要)并且安装了 conda:

First search for what you need to be installing:

首先搜索您需要安装的内容:

$ anaconda search -t conda tesserocr

You will get a few options, you need to look at the platforms and builds to identify what makes sense for you.

您将获得一些选项,您需要查看平台和构建以确定对您有意义的内容。

As I have python 3.6 and linux-64 I chose mcs07/tesserocr

由于我有 python 3.6 和 linux-64,我选择了 mcs07/tesserocr

To install:

安装:

$ conda install -c mcs07 tesserocr

That's it. I didn't need a restart of the terminal or anything. I just kept going.

就是这样。我不需要重启终端或任何东西。我只是继续前进。