I am running kraken on ubuntu 24.04 with python 3.10 in a conda environment.
I am unable to apply kraken models to a pdf document to produce OCR-ed text, using the command indicated in the documentation:
An error arises indicating the module _libvips cannot be found, or the library libvips.so.42:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/pyvips/__init__.py:19 in <module> │
│ │
│ 16 # try to import our binary interface ... if that works, we are in API mode │
│ 17 API_mode = False │
│ 18 try: │
│ ❱ 19 │ import _libvips │
│ 20 │ │
│ 21 │ logger.debug('Loaded binary module _libvips') │
│ 22 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named '_libvips'
During handling of the above exception, another exception occurred:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/ubuntu/anaconda3/envs/con2/bin/kraken:8 in <module> │
│ │
│ 5 from kraken.kraken import cli │
│ 6 if __name__ == '__main__': │
│ 7 │ sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) │
│ ❱ 8 │ sys.exit(cli()) │
│ 9 │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/click/core.py:1157 in __call__ │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/click/core.py:1078 in main │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/click/core.py:1720 in invoke │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/click/core.py:1657 in │
│ _process_result │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/click/core.py:783 in invoke │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/kraken/kraken.py:374 in │
│ process_pipeline │
│ │
│ 371 │ │
│ 372 │ # parse pdfs │
│ 373 │ if format_type == 'pdf': │
│ ❱ 374 │ │ import pyvips │
│ 375 │ │ │
│ 376 │ │ if not batch_input: │
│ 377 │ │ │ logger.warning('PDF inputs not added with batch option. Manual output filena │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/pyvips/__init__.py:61 in <module> │
│ │
│ 58 │ elif _is_mac: │
│ 59 │ │ vips_lib = ffi.dlopen('libvips.42.dylib') │
│ 60 │ else: │
│ ❱ 61 │ │ vips_lib = ffi.dlopen('libvips.so.42') │
│ 62 │ │
│ 63 │ logger.debug('Loaded lib %s', vips_lib) │
│ 64 │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/cffi/api.py:150 in dlopen │
│ │
│ 147 │ │ │ raise TypeError("dlopen(name): name must be a file name, None, " │
│ 148 │ │ │ │ │ │ │ "or an already-opened 'void *' handle") │
│ 149 │ │ with self._lock: │
│ ❱ 150 │ │ │ lib, function_cache = _make_ffi_library(self, name, flags) │
│ 151 │ │ │ self._function_caches.append(function_cache) │
│ 152 │ │ │ self._libraries.append(lib) │
│ 153 │ │ return lib │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/cffi/api.py:834 in │
│ _make_ffi_library │
│ │
│ 831 │
│ 832 def _make_ffi_library(ffi, libname, flags): │
│ 833 │ backend = ffi._backend │
│ ❱ 834 │ backendlib = _load_backend_lib(backend, libname, flags) │
│ 835 │ # │
│ 836 │ def accessor_function(name): │
│ 837 │ │ key = 'function ' + name │
│ │
│ /home/ubuntu/anaconda3/envs/con2/lib/python3.10/site-packages/cffi/api.py:829 in │
│ _load_backend_lib │
│ │
│ 826 │ │ │ "to locate a library called %r" % (name,)) │
│ 827 │ │ if first_error is not None: │
│ 828 │ │ │ msg = "%s. Additionally, %s" % (first_error, msg) │
│ ❱ 829 │ │ raise OSError(msg) │
│ 830 │ return backend.load_library(path, flags) │
│ 831 │
│ 832 def _make_ffi_library(ffi, libname, flags): │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: cannot load library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library()
did not manage to locate a library called 'libvips.so.42'
I have tried installing kraken from the github repository and then installing pyvips manually using pip install pyvips as well as install kraken with the pdf functionality using pip install kraken[pdf]. Both give the above error.
I believe pip-pyvips doesn't ship with the libvips shared library but just tries to load it from the host system. Can you try installing libvips42t64? That will most likely make it work.
Hello,
I am running kraken on ubuntu 24.04 with python 3.10 in a conda environment. I am unable to apply kraken models to a pdf document to produce OCR-ed text, using the command indicated in the documentation:
An error arises indicating the module
_libvips
cannot be found, or the librarylibvips.so.42
:I have tried installing kraken from the github repository and then installing pyvips manually using
pip install pyvips
as well as install kraken with the pdf functionality usingpip install kraken[pdf]
. Both give the above error.