[python] How do I resolve a TesseractNotFoundError?

I am trying to use pytesseract in Python but I always end up with the following error:

    raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

However, pytesseract and Tesseract are installed on my system.

Example code that produces this error:

import cv2
import pytesseract

img = cv2.imread('1d.png')

How do I resolve this TesseractNotFoundError?

This question is related to python python-3.x tesseract python-tesseract

The answer is

I got this error because I installed pytesseract with pip but forget to install the binary.

On Linux

sudo apt update
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev

On Mac

brew install tesseract

On 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. (replace path of tesseract binary if necessary)

references: https://pypi.org/project/pytesseract/ (INSTALLATION section) and https://github.com/tesseract-ocr/tesseract/wiki#installation

I tried adding to the path variable like others have mentioned, but still received the same error. what worked was adding this to my script:

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"

You are probably missing tesseract-ocr from your machine. Check the installation instructions here: https://github.com/tesseract-ocr/tesseract/wiki

On a Mac, you can just install using homebrew:

brew install tesseract

It should run fine after that

Under Windows 10 OS environment, the following method works for me:

  1. https://github.com/tesseract-ocr/tesseract/wiki Download tesseract and install it. Windows version is available here: https://github.com/UB-Mannheim/tesseract/wiki

  2. Find script file pytesseract.py from C:\Users\User\Anaconda3\Lib\site-packages\pytesseract and open it. Change the following code from tesseract_cmd = 'tesseract' to: tesseract_cmd = 'D:/Program Files (x86)/Tesseract-OCR/tesseract.exe'

  3. You may also need add environment variable D:/Program Files (x86)/Tesseract-OCR/

Hope it works for you!

I'm running on a Mac OS and installed tesseract with brew so here's my take on this. Since pytesseract is just how you can access tesseract from python, you have to specify where tesseract is already on your computer.

For Mac OS

Try finding where the tesseract.exe is- if you installed it using brew, on your the terminal use:

>brew list tesseract

This should list where your tesseract.exe is, somewhere more or less like

> /usr/local/Cellar/tesseract/3.05.02/bin/tesseract

Then following their instructions:

pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'

should do the trick!

One simple thing that actually worked for me in Jupyter Notebook, was using double backslash instead of a single backslash in the pytesseract.pytesseract.tesseract_cmd path:

pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'

I face this same issue. I just use this command that will help me.

sudo apt install tesseract-ocr

Note that this will only work on Ubuntu.
sudo is a Unix exclusive command (Linux, Mac, Rasbian, etc.) while apt is Ubuntu specific.

For Mac:

  1. Install Pytesseract (pip install pytesseract should work)
  2. Install Tesseract but only with homebrew, pip installation somehow doesn't work. (brew install tesseract)
  3. Get the path of brew installation of Tesseract on your device (brew list tesseract)
  4. Add the path into your code, not in sys path. The path is to be added along with code, using pytesseract.pytesseract.tesseract_cmd = '<path received in step 3>' - (e.g. pytesseract.pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/4.0.0_1/bin/tesseract')

This should work fine.


I came across this problem today and all the answers mentioned here helped me, but I personally had to dig a lot to solve it. So let me help all others by putting out the solution to it in a very simple form:

  1. Download the executable 64 bit (32-bit if your computer is of 32 bit) exe from here.

    (Name of the file would be tesseract-ocr-w64-setup-v5.0.0.20190526 (alpha))

  1. Install it. Let it install itself in the default C directory.

  2. Now go to your Environment variable (Reach there by just searching it in the start menu or Go to Control Panel > System > Advanced System Settings > Environment Variables)

a) Select PATH and then Edit it. Click on NEW and add the path where it is installed (Usually C:\Program Files\Tesseract-OCR\)

Now you will not get the error!

I faced the same problem. I hope you have installed from here and have also done pip install pytesseract.

If everything is fine you should see that the path C:\Program Files (x86)\Tesseract-OCR where tesseract.exe is available.

Adding Path variable did not helped me, I actually added new variable with name tesseract in environment variables with a value of C:\Program Files (x86)\Tesseract-OCR\tesseract.exe.

Typing tesseract in the command line should now work as expected by giving you usage informations. You can now use pytesseract as such (don't forget to restart your python kernel before running this!):

import pytesseract
from PIL import Image

text = pytesseract.image_to_string(value, config='')    
print("text present in images:",text)


The following three commands will do the needful :

sudo apt update
# This will update your packages
sudo apt install tesseract-ocr
# This will install OCR
sudo apt install libtesseract-dev
# This will add it as development dependency

You can download tesseract-ocr setup using the following link,

Tesseract for windows

Then add new variable with name tesseract in environment variables with value C:\Program Files (x86)\Tesseract-OCR\tesseract.exe

I was also facing the same error when I was trying to make a text-extractor using pytesseract, but the solution was there in installation instructions for pytesseract in pypi site: pytesseract There are many alternatives to avoid the error, But, adding one more parameter in the method pytesseract.image_to_string solved it for me, like

tessdata_dir_config = "/usr/share/tesseract-ocr/4.00/tessdata"
output = pytesseract.image_to_string(image, lang='eng', config=tessdata_dir_config)

Install tesseract from https://github.com/UB-Mannheim/tesseract/wiki and add the path of tesseract.exe to the Path environment variable.

On Ubuntu under flask webframework this should be working

pytesseract.pytesseract.tesseract_cmd = r"/usr/bin/tesseract"
img = Image.open(picture_name)

Most likely you have different versions of Python installed, ensure that the installed Tesseract is on the same Python version.

which pip3 shows you the path to the pip3 installation and which python3 shows the corresponding path to the Python installation.

Ensure that these two are the same.

This occurs under windows (at least in tesseract version 3.05) when the current directory is on a different drive from where tesseract is installed.

Something in tesseract is expecting data files to be in \Program Files... (rather than C:\Program Files, say). So if you're not on the same drive letter as tesseract, it will fail. It would be great if we could work around it by temporarily changing drives (under windows only) to the tesseract installation drive before executing tesseract, and changing back after. Example in your case: You can copy yourmodule_python.py to "C/Program Files (x86)/Tesseract-OCR/" and RUN!

There Are few steps to set the path

1:goto this "https://github.com/UB-Mannheim/tesseract/wiki"

2:download the latest installers

3:install it

4: set the path in system variables such as "C:\Program Files\Tesseract-OCR" or "C:\ProgramFiles (x86)\Tesseract-OCR"

5 : open CMD type "tesseract" and some output except "not regonized type errors"

Small mistake -- I knew I had to open/close my cmd to get the updated path to reflect. Using Jupyter Notebook I had to shutdown the client and re-initialize it also.

Just run these command if you are using linux,

sudo apt update
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev

then run this,

python -m pip install tesseract tesseract-ocr pytesseract

I'm currently using Windows and needed to develop a PDF parser but adding a new environment variable via sysdm.cpl alone did not work. For other Windows user, I strongly suggest adding C:\Program Files (x86)\Tesseract-OCR to your profile.ps1 as well (if using Powershell that is).

Are you importing

from tesseract import image_to_string

Don't import from pytesseract

I was also facing the same issue, just add C:\Program Files (x86)\Tesseract-OCR to your path variable. If it still does not work, add C:\Program Files (x86)\Tesseract-OCR\tessdata to your path variable in a new line. And do not forget to restart your computer after adding the path variable.

Questions with python tag:

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Upgrade to python 3.8 using conda Unable to allocate array with shape and data type How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip How to prevent Google Colab from disconnecting? "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function? "E: Unable to locate package python-pip" on Ubuntu 18.04 Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session' Jupyter Notebook not saving: '_xsrf' argument missing from post How to Install pip for python 3.7 on Ubuntu 18? Python: 'ModuleNotFoundError' when trying to import module from imported package OpenCV TypeError: Expected cv::UMat for argument 'src' - What is this? Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website How to setup virtual environment for Python in VS Code? Pylint "unresolved import" error in Visual Studio Code Pandas Merging 101 Numpy, multiply array with scalar What is the meaning of "Failed building wheel for X" in pip install? Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed Could not install packages due to an EnvironmentError: [Errno 13] OpenCV !_src.empty() in function 'cvtColor' error ConvergenceWarning: Liblinear failed to converge, increase the number of iterations How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How do I install opencv using pip? How do I install Python packages in Google's Colab? How do I use TensorFlow GPU? How to upgrade Python version to 3.7? How to resolve TypeError: can only concatenate str (not "int") to str How can I install a previous version of Python 3 in macOS using homebrew? Flask at first run: Do not use the development server in a production environment TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array What is the difference between Jupyter Notebook and JupyterLab? Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'" How do I resolve a TesseractNotFoundError? Trying to merge 2 dataframes but get ValueError Authentication plugin 'caching_sha2_password' is not supported Python Pandas User Warning: Sorting because non-concatenation axis is not aligned

Questions with python-3.x tag:

Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Replace specific text with a redacted version using Python Upgrade to python 3.8 using conda "Permission Denied" trying to run Python on Windows 10 Python: 'ModuleNotFoundError' when trying to import module from imported package What is the meaning of "Failed building wheel for X" in pip install? How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How to upgrade Python version to 3.7? TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array How do I resolve a TesseractNotFoundError? Could not find a version that satisfies the requirement tensorflow Not able to pip install pickle in python 3.6 json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 190) installing urllib in Python3.6 pip install returning invalid syntax Unable to import path from django.urls Display all dataframe columns in a Jupyter Python Notebook How to make Firefox headless programmatically in Selenium with Python? How to import cv2 in python3? Pipenv: Command Not Found Error in Python script "Expected 2D array, got 1D array instead:"? Fixed digits after decimal with f-strings How do I upgrade the Python installation in Windows 10? Pip error: Microsoft Visual C++ 14.0 is required Python error message io.UnsupportedOperation: not readable Anaconda Installed but Cannot Launch Navigator Conda command is not recognized on Windows 10 TypeError: can't pickle _thread.lock objects How do you fix the "element not interactable" exception? How to print a specific row of a pandas DataFrame? Relative imports - ModuleNotFoundError: No module named x SyntaxError: unexpected EOF while parsing ImportError: No module named 'django.core.urlresolvers' Why Python 3.6.1 throws AttributeError: module 'enum' has no attribute 'IntFlag'? What is the purpose of "pip install --user ..."? Add Legend to Seaborn point plot How to install pip for Python 3.6 on Ubuntu 16.10? Python sockets error TypeError: a bytes-like object is required, not 'str' with send function WinError 2 The system cannot find the file specified (Python) Python 3.6 install win32api? error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte Python 3 - ValueError: not enough values to unpack (expected 3, got 2) matplotlib: plot multiple columns of pandas data frame on the bar chart Unable to set default python version to python3 in ubuntu TypeError: '<=' not supported between instances of 'str' and 'int' pandas: merge (join) two data frames on multiple columns Replacing a character from a certain index Scrolling to element using webdriver?

Questions with tesseract tag:

Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this? How do I resolve a TesseractNotFoundError? best OCR (Optical character recognition) example in android Tesseract OCR simple example Tesseract running error image processing to improve tesseract OCR accuracy How to make tesseract to recognize only numbers, when they are mixed with letters?

Questions with python-tesseract tag:

How do I resolve a TesseractNotFoundError?