How to install Tesseract from git source on CentOS 7 avoiding the error “configure: error: Leptonica 1.74 or higher is required.”

As you might know, from epel repository on CentOS 7 user is able to install tesseract 3.0.4 which also automatically installs leptonica 1.72. And if you want to install the higher or the latest version of tesseract you’ve to install both of them from source.

At first install some prerequisites:

yum install libpng-devel libtiff-devel libjpeg-devel automake ca-certificates g++ git libtool make pkg-config unzip 

// install git if not already installed
yum install git

Then install Leptonica at least 1.74 from http://leptonica.org/download.html

cd /any/directory
wget http://leptonica.org/source/leptonica-1.79.0.tar.gz
tar -xf leptonica-1.80.0.tar.gz
./configure --prefix=/usr/local/
make
make install

In case if you’ve already installed old version, you might see the error message like:

ln: failed to create symbolic link ‘libleptonica.a’: File exists
ln: failed to create symbolic link ‘libleptonica.la’: File exists
ln: failed to create symbolic link ‘libleptonica.so’: File exists

In this case remove the previous version of Leptonica (and if error still occurs, just delete the files)

yum remove leptonica

After, to make leptonica available you must configure the environment variables

vim /etc/profile

// ad this at the end of the file
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LIBLEPT_HEADERSDIR=/usr/local/include
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

// and update env
source /etc/profile

Now download and install Tesseract by following the official documentation:

wget https://github.com/tesseract-ocr/tesseract/archive/refs/tags/4.1.1.zip
unzip 4.1.1.zip
./configure --prefix=/usr/local/
./autogen.sh
./configure --with-extra-includes=/usr/local/include --with-extra-libraries=/usr/local/include
make
make install

And finally, check the installed tesseract version by running the command:

tesseract --version

And you should get something like this:

tesseract 4.1.1
 leptonica-1.80.0
  libjpeg 9d : libpng 1.6.37 : libtiff 4.0.3 : zlib 1.2.7 : libwebp 1.1.0

@sources:

https://tesseract-ocr.github.io/tessdoc/Compiling-%E2%80%93-GitInstallation.html
https://github.com/tesseract-ocr/tesseract/releases
http://leptonica.org/download.html

Leave a Reply