OSError: [Errno 2] There is no such file or directory using pytesser

This is my problem, I want to use pytesser to get the contents of the image. My operating system is Mac OS 10.11, and I already installed PIL, pytesser, tesseract-ocr engine and other supporting libraries like libpng etc. But when I run my code as shown below, an error occurs.

from pytesser import * import os image = Image.open('/Users/Grant/Desktop/1.png') text = image_to_string(image) print text 

Then an error message appears

 Traceback (most recent call last): File "/Users/Grant/Documents/workspace/image_test/image_test.py", line 10, in <module> text = image_to_string(im) File "/Users/Grant/Documents/workspace/image_test/pytesser/pytesser.py", line 30, in image_to_string call_tesseract(scratch_image_name, scratch_text_name_root) File "/Users/Grant/Documents/workspace/image_test/pytesser/pytesser.py", line 21, in call_tesseract retcode = subprocess.call(args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call return Popen(*popenargs, **kwargs).wait() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory 

In addition, tesseract-ocr works well on my Mac, I can run it in the terminal and get the result. Below is the result of the test image. tesseract result

Can someone help me with this question please?

+5
source share
7 answers

Open the pytesseract.py file.

Mina is located in /Users/yourUser/.virtualenvs/cv/lib/python2.7/site-packages/pytesseract/pytesseract.py

Change tesseract_cmd = 'tesseract' to tesseract_cmd = '/usr/local/bin/tesseract'

+7
source

Fortunately, I decided this one.

First i run the command

 pip install pytesseract 

to install the package.

But I get the error "There is no such file or directory using pytesser."

Then I read this link: image_to_string does not work on Mac So, just run the following script:

 brew link libtiff brew link libpng brew link jpeg brew install tesseract 

Worked for me ~

+5
source

I had the same problem, but I was able to convert the image to a string. using apt-get should do the trick:

 sudo apt-get install tesseract-ocr 

and if you cannot use it in a python script, just do this:

 from os import system system("tesseract -l eng /image.png text.txt") 
+2
source

You need to install tesseract-ocr:

sudo apt-get install tesseract-ocr

And in the script

  from PIL import Image import os import pytesseract text = pytesseract.image_to_string(Image.open(os.path.abspath('test.png'))) 
+1
source

This may not be for everyone, but I had a similar problem, and this was due to getting errors when installing tesseract. I kept getting the error message:

 Making install in ccutil /bin/sh: /Applications/Xcode: No such file or directory make: *** [install-recursive] Error 1 

This was due to the fact that I had previously renamed / Applications / Xcode to / Applications / Xcode 8 to make it easier to distinguish between the different versions of Xcode installed on my system.

I temporarily renamed it back to / Applications / Xcode and ran the command

 sudo xcode-select --switch /Applications/Xcode.app 

Then, finally, he tried to reinstall tesseract and, fortunately, this time did not receive error messages.

 brew install tesseract --all-languages 

Now the Python code is working fine, and I did not receive the error message "OSError: [Errno 2] No such file or directory.

0
source

You get an exception because the subprocess cannot find the binaries (tesser executable).

Installation is a three-step process:

1. Download / install the libs / binaries system levels :

For different OSs, help here. For MacOS, you can directly install it using brew.

Install Google Tesseract OCR (additional information on how to install the engine on Linux, Mac OSX, and Windows). You should be able to refer to tesseract as tesseract. If this is not the case, for example because tesseract is not in your PATH, you will have to change "tesseract_cmd" at the top of tesseract.py. Under Debian / Ubuntu, you can use the tesseract-ocr package. For Mac OS Users. please install tesseract homeprew package.


2. Install the Python package

 pip install pytesseract 

3. Finally, you need to have the tesseract binary in PATH .

Or you can install it at runtime:

 import pytesseract pytesseract.pytesseract.tesseract_cmd = '<path-to-tesseract-bin>' 

The default path is' d be /usr/local/bin/tesseract

0
source

I am facing the same issue twice for both MacOS and Ubuntu. It worked with me. Hope this helps.

First open a terminal, and then:

0
source

Source: https://habr.com/ru/post/1243778/


All Articles