Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

python - How to solve error importing pytesseract - f"{tesseract_cmd} is not installed or it's not in your PATH."

I've installed tesseract from https://github.com/UB-Mannheim/tesseract/wiki Following this I also installed pip install pytesseract and also pip install tesseract

I've included "C:Program FilesTesseract-OCR" in my PATH in the environment variables.

When I execute the following code:

import pytesseract
pytesseract.pytesseract.tesseract_cmd = r"C:Program FilesTesseract-OCResseract.exe"
print(pytesseract.image_to_string(Image.open('News.png')))

I get an error in the first line as follows:

Traceback (most recent call last):
  File "C:Users...DocumentsProjectBreachTesseract_import2.py", line 1, in <module>
    import pytesseract
  File "C:Python27libsite-packagespytesseract\__init__.py", line 2, in <module>
    from .pytesseract import ALTONotSupported
  File "C:Python27libsite-packagespytesseractpytesseract.py", line 89
    f"{tesseract_cmd} is not installed or it's not in your PATH."
                                                                ^
SyntaxError: invalid syntax
[Finished in 0.3s with exit code 1]

I can use tesseract using Command Prompt and get the required results, however, it doesn't work on python for me. I am using SublimeText3 for writing my script.

I've also tried using pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...