9951 explained code solutions for 126 technologies


tesseract-ocrHow do I set the Tesseract OCR environment variable?


The Tesseract OCR environment variable can be set in a few different ways.

  1. Using the export command in the command line:
export TESSDATA_PREFIX=/usr/local/share/tessdata
  1. Adding the export command to the ~/.profile file:
echo 'export TESSDATA_PREFIX=/usr/local/share/tessdata' >> ~/.profile
  1. Setting the environment variable in the application code:
# Python
import os
os.environ["TESSDATA_PREFIX"] = "/usr/local/share/tessdata"

# Java
System.setProperty("TESSDATA_PREFIX", "/usr/local/share/tessdata");

The environment variable TESSDATA_PREFIX should be set to the path of the Tesseract data files.

Helpful links

Edit this code on GitHub