tesseract: unclear "leptonica not found" message

$ sudo apt-get install liblept4
Reading package lists... Done
Building dependency tree       
Reading state information... Done
liblept4 is already the newest version.
liblept4 set to manually installed.
The following packages were automatically installed and are no longer required:
  linux-image-4.2.0-23-generic linux-image-extra-4.2.0-23-generic
  linux-signed-image-4.2.0-23-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.
teo@xxx1:~/temp/tesseract$ ./configure 
checking for g++... g++
...
checking for mbstate_t... yes
checking for leptonica... configure: error: leptonica not found

OR the error message needs to be more precise about how to get leptonica

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (4 by maintainers)

Most upvoted comments

@teo1978: this is standard autotools error message. You will get it for all libraries. ./configure is tool not a teacher. Name of needed package could be different base on distribution.

If you are not familiar with compiling software on your operation system it is not tesseract problem.

Thanks a lot, adgaudio! I was getting the error message “configure: error: Leptonica 1.74 or higher is required.” Try to install libleptonica-dev package". Your solution worked like a charm!!!

I know this is an old closed issue, but I found a solution to this issue and will share my solution, since it was not obvious.

The short summary: I tried building latest tesseract (and leptonica) from source using cmake for both libs. The tesseract cmake step could not find leptonica. My solution was to set PKG_CONFIG_PATH before cmake. My exact steps to address the problem are below.

I will assume you have installed other pre-requisites (like giflib) as specified by both libraries.

After pre-requisites, I installed Leptonica to a custom location:

export INSTALL_PREFIX=~/.sources
git clone https://github.com/DanBloomberg/leptonica.git
mkdir leptonica/build ; cd leptonica/build
cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DBUILD_PROG=1 ..
make
make install

Then, I installed Tesseract to the same custom location. Note the use of PKG_CONFIG_PATH.

export INSTALL_PREFIX=~/.sources
git clone https://github.com/tesseract-ocr/tesseract.git
mkdir tesseract/build ; cd tesseract/build
PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX/lib ..
make
make install

Finally, I use tesseract by exporting these variables in my bash profile. The only one you probably need is PATH…

export LD_LIBRARY_PATH=$HOME/.sources/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$HOME/.sources/lib:$HOME/.sources/lib64:$LIBRARY_PATH
export INSTALL_PREFIX=$HOME/.sources
export PATH=$HOME/.sources/bin:$PATH

And an example run:

git clone https://github.com/tesseract-ocr/tessdata.git
tesseract --tessdata-dir ./tessdata -l heb ./tesseract/testing/hebrew.png out
cat out.txt 

A single file containing all above code is here: https://gist.github.com/adgaudio/f772004444dc808e900c057d45f8b52e

FYI: If you prefer to use the ./autogen.sh approach, you should be able to replace ./configure with PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig ./configure --prefix=$INSTALL_PREFIX --with-extra-libraries=$INSTALL_PREFIX/lib. (I just tried it and it worked).

I hope you find this helpful 😃

Please use Tesseract users forum and ask this question (and other questions you might have) there.

What about fixing the bug instead, so that the error message is clear enough and there’s nothing to figure out?