Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytesseract-no such file or directory error

Tags:

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

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??

like image 489
chaitanya90 Avatar asked Feb 26 '15 11:02

chaitanya90


People also ask

How do I import Pytesseract into Jupyter notebook?

Create a Python script (a . py-file), or start up a Jupyter notebook. At the top of the file, import pytesseract , then point pytesseract at the tesseract installation you discovered in the previous step. Note the r' ' at the start of the string that defines the file location.

How do you find the Pytesseract path?

Default installation path at the time of this edit was: C:\Users\USER\AppData\Local\Tesseract-OCR. It may change so please check the installation path.


3 Answers

You need to install tesseract-ocr:

sudo apt-get install tesseract-ocr
like image 87
Padraic Cunningham Avatar answered Nov 08 '22 13:11

Padraic Cunningham


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

pip install tesseract-ocr

like image 27
Shaz Avatar answered Nov 08 '22 13:11

Shaz


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

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

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

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.

like image 31
agent18 Avatar answered Nov 08 '22 14:11

agent18