TesseractNotFoundError: <full_path_to_your_tesseract_executable> 未安装或不在PATH中。

问题描述 投票:0回答:1

当我打开图像和数字化,然后它给出了错误,我在jupyter笔记本Windows 10上运行这个代码。我已经安装了pytesseract和tesseract,也使用pip命令。

这是我的代码

    try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract

# If you don't have tesseract executable in your PATH, include the following:
# pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
# Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'

# Simple image to string
print(pytesseract.image_to_string(Image.open('Train/TR_1.jpg')))

当我运行给定的代码时,它给出了错误

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
    237     try:
--> 238         proc = subprocess.Popen(cmd_args, **subprocess_args())
    239     except OSError as e:

~\anaconda3\envs\tf1\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    799                                 errread, errwrite,
--> 800                                 restore_signals, start_new_session)
    801         except:

~\anaconda3\envs\tf1\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1206                                          os.fspath(cwd) if cwd is not None else None,
-> 1207                                          startupinfo)
   1208             finally:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

TesseractNotFoundError                    Traceback (most recent call last)
<ipython-input-24-518675d4cb18> in <module>
     10 
     11 # Simple image to string
---> 12 print(pytesseract.image_to_string(Image.open('Train/TR_1.jpg')))
     13 
     14 # # French text image to string

~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in image_to_string(image, lang, config, nice, output_type, timeout)
    358         Output.DICT: lambda: {'text': run_and_get_output(*args)},
    359         Output.STRING: lambda: run_and_get_output(*args),
--> 360     }[output_type]()
    361 
    362 

~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in <lambda>()
    357         Output.BYTES: lambda: run_and_get_output(*(args + [True])),
    358         Output.DICT: lambda: {'text': run_and_get_output(*args)},
--> 359         Output.STRING: lambda: run_and_get_output(*args),
    360     }[output_type]()
    361 

~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in run_and_get_output(image, extension, lang, config, nice, timeout, return_bytes)
    268         }
    269 
--> 270         run_tesseract(**kwargs)
    271         filename = kwargs['output_filename_base'] + extsep + extension
    272         with open(filename, 'rb') as output_file:

~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
    240         if e.errno != ENOENT:
    241             raise e
--> 242         raise TesseractNotFoundError()
    243 
    244     with timeout_manager(proc, timeout) as error_string:

TesseractNotFoundError: <full_path_to_your_tesseract_executable> is not installed or it's not in your PATH

我在jupyter笔记本windows 10上运行这段代码,我已经安装了pytesseract和tesseract,也使用pip命令。我已经安装了pytesseract和tesseract,也使用pip命令。

opencv image-processing computer-vision tesseract python-tesseract
1个回答
0
投票

你必须先安装tesseract本身。在Centos中,你调用做这个通过运行

yum-config-manager --add-repo 
https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/
rpm --import https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key
yum install -y tesseract  tesseract-langpack-deu

在windows操作系统中应该也有一个类似的版本,可以在这里找到。https:/github.comtesseract-ocrtesseractwiki。

pytesseract 只是 tesseract 包的一个包装。


0
投票

试着加入这行,加上路径(例如)。

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract'

之前

print(pytesseract.image_to_string(Image.open('Train/TR_1.jpg')))

之前已经下载并安装了windows的可执行文件。https:/github.comtesseract-ocrtesseractwiki。

© www.soinside.com 2019 - 2024. All rights reserved.