Running the sample code in pytesseract
Question: I am running python 2.6.6 and want to install the
[pytesseract](https://pypi.python.org/pypi/pytesseract) package. After
extraction and installation, I can call the pytesseract from the command line.
However I want to run the tesseract within python. I have the following code
(ocr.py):

    
    
    try:
         import Image
    except ImportError:
         from PIL import Image
    import pytesseract
    print(pytesseract.image_to_string(Image.open('test.png')))
    print(pytesseract.image_to_string(Image.open('test-european.jpg'),lang='fra'))
    

When I run the code by python ocr.py, I get the following output:

    
    
    Traceback (most recent call last):
      File "ocr.py", line 6, in <module>
        print(pytesseract.image_to_string(Image.open('test.png')))
      File "/pytesseract-0.1.6/build/lib/pytesseract/pytesseract.py", line 164, in image_to_string
        raise TesseractError(status, errors)
    pytesseract.TesseractError: (2, 'Usage: python tesseract.py [-l language] input_file')
    

test.png and test-european.jpg are in the working directory. Can Someone help
me running this code? I have tried the following:

  1. Adjusted the tesseract_cmd to 'pytesseract'
  2. Installed tesseract-ocr

Any help is appreciated as I am trying to solve this problem for hours now.


Answer: `tesseract_cmd` should point to the command line program
[`tesseract`](https://github.com/tesseract-ocr/tesseract), not `pytesseract`.

For instance on Ubuntu you can install the program using:

    
    
    sudo apt install tesseract-ocr
    

And then set the variable to just `tesseract` or `/usr/bin/tesseract`.

