Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python : OSError: [Errno 2] No such file or directory

I am using pytesseract lib to extract text from image. This works fine when I am running code on localhost. But gives me above error when I deploy on openshift.

Below is code what I have written so far.

try:
  import Image
except ImportError:
  from PIL import Image
import pytesseract
filePath = PATH_WHERE_FILE_IS_LOCATED # '/var/lib/openshift/555.../app-root/data/data/y.jpg'
text = pytesseract.image_to_string(Image.open(filePath))  # this line produces error

Traceback of above error is

>>> pytesseract.image_to_string(Image.open(filePath))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/var/lib/openshift/56faaee42d527151d5000089/app-  root/runtime/repo/pytesseract/pytesseract.py", line 132, in  image_to_string
boxes=boxes)
File "/var/lib/openshift/56faaee42d527151d5000089/app-root/runtime/repo/pytesseract/pytesseract.py", line 73, in run_tesseract
stderr=subprocess.PIPE)
File "/opt/rh/python27/root/usr/lib64/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/rh/python27/root/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

But Image.open(filePath) returns object reference

 <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=1366x768 at 0x7FC5A9F719D0>

How to remove this error ? thanks in advance!!

like image 747
Suraj Palwe Avatar asked Apr 14 '16 13:04

Suraj Palwe


People also ask

How do I fix Errno 2 No such file or directory in Python?

The Python FileNotFoundError: [Errno 2] No such file or directory error is often raised by the os library. This error tells you that you are trying to access a file or folder that does not exist. To fix this error, check that you are referring to the right file or folder in your program.

How do I fix No such file or directory?

In some cases, this error could be shown when the path of the specified file or folders exceeds 258 characters in length. The way to solve this is to reduce the length of the full path to the items specified, either by moving or renaming the file(s) and/or containing folders.

What is errno2?

The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory.


2 Answers

Either you don't have tesseract-ocr installed on "openshift", or it is not in your PATH. See https://pypi.python.org/pypi/pytesseract/0.1 Check that you can execute tesseract command from command line.

like image 82
Konstantin Svintsov Avatar answered Oct 06 '22 02:10

Konstantin Svintsov


As mentioned here install tesseract-ocr

You can rhc ssh to run commands. More windows specific details can be found here.

like image 41
LearnerEarner Avatar answered Oct 06 '22 03:10

LearnerEarner