i have installed the tasseract using
pip install pytesseract
whenever i tried to run this piece of code
from PIL import Image
import pytesseract
im = Image.open('hasan1.jpg')
print (pytesseract.image_to_string(im))
I got these errors.
Traceback (most recent call last):
File "ocr.py", line 34, in <module>
text = pytesseract.image_to_string(Image.open(filename))
File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
packages/pytesseract/pytesseract.py", line 193, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)
File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
packages/pytesseract/pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
packages/pytesseract/pytesseract.py", line 111, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'
I believe PyTesseract requires you to have the tesseract library installed on your system - PyTesseract is trying to run the command-line interface but it can't find it presumably because you have only installed the python bindings.
If you are on an Ubuntu/Debian-based system, you can try:
sudo apt-get install tesseract-ocr
You can check the Tesseract installation docs for more info: https://github.com/tesseract-ocr/tesseract/wiki
Related
I'm trying to use pytesseract library on linux but receiving the following error.
How to solve this error log
Traceback (most recent call last):
File "/home/rawnewton/.local/lib/python3.10/site-packages/pytesseract/pytesseract.py", line 254, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'System_path_to_tesseract.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/2E50C9C750C995CD/Projects/Public/MajorProject/image_text.py", line 58, in <module>
text = pytesseract.image_to_string(cropped)
File "/home/rawnewton/.local/lib/python3.10/site-packages/pytesseract/pytesseract.py", line 416, in image_to_string
return {
File "/home/rawnewton/.local/lib/python3.10/site-packages/pytesseract/pytesseract.py", line 419, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "/home/rawnewton/.local/lib/python3.10/site-packages/pytesseract/pytesseract.py", line 286, in run_and_get_output
run_tesseract(**kwargs)
File "/home/rawnewton/.local/lib/python3.10/site-packages/pytesseract/pytesseract.py", line 258, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: System_path_to_tesseract.exe is not installed or it's not in your PATH. See README file for more information.
I have installed it using the following commands:
pip install tesseract
pip install tesseract-ocr
I am using Xubuntu version 20.04.
import pytesseract
from PIL import Image
img = Image.open('image1.jpg')
result = pytesseract.image_to_string(img)
print(result)
My question is may similar to this and this. But, there's no helpful answer for me...
Error :
Traceback (most recent call last):
File "/home/istiak/PycharmProjects/image-to-text/venv/lib64/python3.9/site-packages/pytesseract/pytesseract.py", line 255, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "/usr/lib64/python3.9/subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib64/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/istiak/PycharmProjects/image-to-text/main.py", line 6, in
result = pytesseract.image_to_string(img)
File "/home/istiak/PycharmProjects/image-to-text/venv/lib64/python3.9/site-packages/pytesseract/pytesseract.py", line 409, in image_to_string
return {
File "/home/istiak/PycharmProjects/image-to-text/venv/lib64/python3.9/site-packages/pytesseract/pytesseract.py", line 412, in
Output.STRING: lambda: run_and_get_output(*args),
File "/home/istiak/PycharmProjects/image-to-text/venv/lib64/python3.9/site-packages/pytesseract/pytesseract.py", line 287, in run_and_get_output
run_tesseract(**kwargs)
File "/home/istiak/PycharmProjects/image-to-text/venv/lib64/python3.9/site-packages/pytesseract/pytesseract.py", line 259, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
But, I have pytesseract right there..
I found this helpful for him. But, I am using Linux Fedora... Is there something just like this in Linux?
I tried to install tesseract-ocr link......
sudo snap install tesseract-ocr
sudo dnf install tesseract-ocr
Error : Unable to find a match: tesseract-ocr
sudo dnf install tesseract
If you are using Windows than you need to install Tesseract #Bhargav gave that link. If you are using Ubuntu, Mint or something else..
You have to try
sudo apt-get install tesseract-ocr
If you are using Arch than, visit the link
I am using Pytesseract to read a specific part of a PDF. Following is my code to configure tesseract into my code.
pytesseract.pytesseract.tesseract_cmd = os.path.join(cwd, "Tesseract-OCR\\tesseract.exe")
cwd is the same directory where my SplitPDF.py file and the Tesseract-OCR (which contains tesseract.exe) folder are present.
When I execute SplitPDF.py everything works fine and I have my desired output.
But the problem occurs when I create SplitPDF.exe (using Pyinstaller) I am getting an error that says tesseract.exe is not installed or it's not in your path.
Following is the complete error:
Traceback (most recent call last): File
"site-packages\pytesseract\pytesseract.py", line 223, in run_tesseract
File "subprocess.py", line 775, in init File "subprocess.py",
line 1178, in _execute_child FileNotFoundError: [WinError 2] The
system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "tkinter__init__.py", line
1705, in call File "PDF_Splitter.py", line 241, in UploadAction1
pdfsplitbylca(entryString) File "Split_by_LCA_1.py", line 155, in
pdfsplitbylca text = pytesseract.image_to_string(im, lang = 'eng')
File "site-packages\pytesseract\pytesseract.py", line 345, in
image_to_string File "site-packages\pytesseract\pytesseract.py", line
344, in File "site-packages\pytesseract\pytesseract.py", line
253, in run_and_get_output File
"site-packages\pytesseract\pytesseract.py", line 225, in run_tesseract
pytesseract.pytesseract.TesseractNotFoundError:
C:\Users\VADIRA~1.KAT\AppData\Local\Temp_MEI370202\Tesseract-OCR\tesseract.exe
is not installed or it's not in your path
Am I not creating the .exe correctly or is there a better way to configure Tesseract?
You should consider using the Pytesseract library (tesseract python library) instead of the executable. I hope this helped. The usage is pretty easy. you will have to install it first but to use
import pytesseract
from PIL import Image
pytesseract.image_to_string(Image.open('image'))
Hope this helps
I was trying to install gdal in python 3.6.1, but getting the following error. How to overcome this?
bibinwilson ~ $ pip3 install gdal
Collecting gdal Downloading GDAL-2.2.1.tar.gz (475kB)
100% |████████████████████████████████| 481kB 397kB/s
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/GDAL.egg-info
writing pip-egg-info/GDAL.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/GDAL.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/GDAL.egg-info/top_level.txt
writing manifest file 'pip-egg-info/GDAL.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Traceback (most recent call last):
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 131, in fetch_config
p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py",
line 707, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py",
line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '../../apps/gdal-config'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 179, in get_gdal_config
return fetch_config(option, gdal_config = self.gdal_config)
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 135, in fetch_config
raise gdal_config_error(e)
__main__.gdal_config_error: [Errno 2] No such file or directory: '../../apps/gdal-config'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 131, in fetch_config
p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py",
line 707, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py",
line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'gdal-config'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 339, in <module>
**extra )
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py",
line 148, in setup
dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py",
line 955, in run_commands
self.run_command(cmd)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py",
line 974, in run_command
cmd_obj.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/egg_info.py",
line 279, in run
self.find_sources()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/egg_info.py",
line 306, in find_sources
mm.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/egg_info.py",
line 533, in run
self.add_defaults()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/egg_info.py",
line 562, in add_defaults
sdist.add_defaults(self)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/py36compat.py",
line 36, in add_defaults
self._add_defaults_ext()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/py36compat.py",
line 119, in _add_defaults_ext
build_ext = self.get_finalized_command('build_ext')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py",
line 299, in get_finalized_command
cmd_obj.ensure_finalized()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py",
line 107, in ensure_finalized
self.finalize_options()
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 214, in finalize_options
self.gdaldir = self.get_gdal_config('prefix')
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 188, in get_gdal_config
return fetch_config(option)
File "/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/setup.py",
line 135, in fetch_config
raise gdal_config_error(e)
__main__.gdal_config_error: [Errno 2] No such file or directory: 'gdal-config'
---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in
/private/var/folders/43/7yqv__4j5776m508kggs_dxm0000gn/T/pip-build-naebgem9/gdal/
I had this error and installing GDAL through Homebrew fixed this for me. Installing the the binaries for GDAL didn't correct the error but once I installed through brew it was resolved.
brew install gdal
seems like the same issue as here: Python GDAL: pip install --no-install GDAL fails
If you've already installed the binaries (like I had) then this answer worked for me: https://stackoverflow.com/a/44051123/3969685
This simple procedure seemed to work for me on MAC sierra, python 3.6, GDAL 2.2.3
1) Install GDAL framework using dmg installer for MAC [GDAL MAC
Frameworks]: http://www.kyngchaos.com/software/frameworks
2) Add gdal-config folder to your path and get your version:
$ export PATH=/Library/Frameworks/GDAL.framework/Versions/2.2/Programs:$PATH
$ gdal-config --version
3) Use pip to install the version reported by gdal-config --version:
$ pip install gdal==2.2.3
Step 1 Seems to set up the python site-packages under its install framework folders and I think you could copy them to your python site-packages. But better to use pip install.
This simple procedure seemed to work for me on MAC
Install GDAL framework using Brew
> brew install gdal
gdal-config --version
gdal-config --version
2.4.4
3. GDAL Python binding
pip3 install gdal==2.4.4
Note the GDAL version of the end of the command, it must be the same as the obtained in the step above using gdal-config. To avoid conflicts or any further issues, it’s important to install and use the exact versions that any component will require.
I created a virtualenv via command venv. Then I installed tesseract via command brew install tesseract. But I can use it only on actual env, when I use it on virtualenv, an error No such file or directory: 'tesseract' is thrown:
BlockquoteTraceback (most recent call last):
File "/Users/abc/PycharmProjects/spider/demo2.py", line 5, in <module>
vcode = pytesseract.image_to_string(image)
File "/Users/abc/env1/lib/python3.5/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
config=config)
File "/Users/abc/env1/lib/python3.5/site-packages/pytesseract/pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'