Python Pytesseract:“TesseractNotFound 错误:tesseract 未安装或不在您的路径中”,我该如何解决?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50951955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this?
提问by Jed Bartlet
I'm trying to run a basic and very simple code in python.
我正在尝试在 python 中运行一个基本且非常简单的代码。
from PIL import Image
import pytesseract
im = Image.open("sample1.jpg")
text = pytesseract.image_to_string(im, lang = 'eng')
print(text)
This is what it looks like, I have actually installed tesseract for windows through the installer. I'm very new to Python, and I'm unsure how to proceed?
这就是它的样子,我实际上已经通过安装程序为 Windows 安装了 tesseract。我对 Python 很陌生,我不确定如何继续?
Any guidance here would be very helpful. I've tried restarting my Spyder application but to no avail.
这里的任何指导都会非常有帮助。我试过重新启动我的 Spyder 应用程序,但无济于事。
回答by Nafeez Quraishi
I see steps are scattered in different answers. Based on my recent experience with this pytesseract error on Windows, writing different steps in sequence to make it easier to resolve the error:
我看到步骤分散在不同的答案中。根据我最近在 Windows 上遇到此 pytesseract 错误的经验,按顺序编写不同的步骤以更容易解决错误:
1. Install tesseract using windows installer available at: https://github.com/UB-Mannheim/tesseract/wiki
1. 使用 Windows 安装程序安装 tesseract:https: //github.com/UB-Mannheim/tesseract/wiki
2. Note the tesseract path from the installation.Default installation path at the time the time of this edit was: C:\Users\USER\AppData\Local\Tesseract-OCR
. It may change so please check the installation path.
2. 请注意安装中的 tesseract 路径。此编辑时的默认安装路径为:C:\Users\USER\AppData\Local\Tesseract-OCR
。它可能会改变,所以请检查安装路径。
3. pip install pytesseract
3.pip install pytesseract
4. Set the tesseract path in the script before calling image_to_string
:
4. 在调用之前在脚本中设置 tesseract 路径image_to_string
:
pytesseract.pytesseract.tesseract_cmd = r'C:\Users\USER\AppData\Local\Tesseract-OCR\tesseract.exe'
pytesseract.pytesseract.tesseract_cmd = r'C:\Users\USER\AppData\Local\Tesseract-OCR\tesseract.exe'
回答by Ali
First you should install binary:
首先你应该安装二进制文件:
On Linux
在 Linux 上
sudo apt-get update
sudo apt-get install tesseract-ocr
sudo apt-get install libtesseract-dev
On Mac
在 Mac 上
brew install tesseract
On Windows
在 Windows 上
download binary from https://github.com/UB-Mannheim/tesseract/wiki. then add pytesseract.pytesseract.tesseract_cmd = 'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
to your script.
从https://github.com/UB-Mannheim/tesseract/wiki下载二进制文件。然后添加pytesseract.pytesseract.tesseract_cmd = 'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
到您的脚本中。
Then you should install python package using pip:
然后你应该使用 pip 安装 python 包:
pip install tesseract
pip install tesseract-ocr
references: https://pypi.org/project/pytesseract/(INSTALLATION section) and https://github.com/tesseract-ocr/tesseract/wiki#installation
参考资料:https: //pypi.org/project/pytesseract/(安装部分)和 https://github.com/tesseract-ocr/tesseract/wiki#installation
回答by Mujeeb Ishaque
For Windows Only
仅适用于 Windows
1 - You need to have Tesseract OCR installed on your computer.
1 - 您需要在您的计算机上安装 Tesseract OCR。
get it from here. https://github.com/UB-Mannheim/tesseract/wiki
Download the suitable version.
从这里得到它。 https://github.com/UB-Mannheim/tesseract/wiki
下载合适的版本。
2 - Add Tesseract path to your System Environment. i.e. Edit system variables.
2 - 将 Tesseract 路径添加到您的系统环境。即编辑系统变量。
3 - Run pip install pytesseract
and pip install tesseract
3 - 运行pip install pytesseract
和pip install tesseract
4 - Add this line to your python script every time
4 -每次都将此行添加到您的 python 脚本中
pytesseract.pytesseract.tesseract_cmd = 'C:/OCR/Tesseract-OCR/tesseract.exe' # your path may be different
5 - Run the code.
5 - 运行代码。
回答by GeorgPoe
From https://pypi.org/project/pytesseract/:
从https://pypi.org/project/pytesseract/:
pytesseract.pytesseract.tesseract_cmd = '<full_path_to_your_tesseract_executable>'
# Include the above line, if you don't have tesseract executable in your PATH
# Example tesseract_cmd: 'C:\Program Files (x86)\Tesseract-OCR\tesseract'
回答by Kumar S
In windows:
在窗口中:
pip install tesseract
pip 安装 tesseract
pip install tesseract-ocr
pip 安装 tesseract-ocr
and check the file which is stored in your system usr/appdata/local/programs/site-pakages/python/python36/lib/pytesseract/pytesseract.py file and compile the file
并检查系统中存储的文件 usr/appdata/local/programs/site-pakages/python/python36/lib/pytesseract/pytesseract.py 文件并编译该文件
回答by fuwiak
On Mac, you can install it like shown below. This works for me.
在 Mac 上,您可以如下所示安装它。这对我有用。
brew install tesseract
回答by Joubert Junior
I can solve it by updating the tesseract_cmd variable with the bin/tesseract path in the pytesseract.py file
我可以通过使用 pytesseract.py 文件中的 bin/tesseract 路径更新 tesseract_cmd 变量来解决它
回答by Kumar S
you can install this package... https://github.com/UB-Mannheim/tesseract/wikiafter that you should go this path C:\Program Files (x86)\Tesseract-OCR\ tesseract.exe then run tesseract file. I think this will help you...
你可以安装这个包... https://github.com/UB-Mannheim/tesseract/wiki之后你应该去这个路径 C:\Program Files (x86)\Tesseract-OCR\ tesseract.exe 然后运行 tesseract 文件. 我想这会帮助你...
回答by Kenstars
You would be needing to install tesseract.
您将需要安装tesseract。
Check out the above documentation on the installation.
查看以上有关安装的文档。
回答by Asaga
On Windows 64 bits, just add the following to the PATH environment variable:
"C:\Program Files\Tesseract-OCR"
and it will work.
在 Windows 64 位上,只需将以下内容添加到 PATH 环境变量中:
"C:\Program Files\Tesseract-OCR"
它就会起作用。