mindee / doctr

docTR (Document Text Recognition) - a seamless, high-performing & accessible library for OCR-related tasks powered by Deep Learning.
https://mindee.github.io/doctr/
Apache License 2.0
3.54k stars 416 forks source link

cannot load library 'pango-1.0': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0' #815

Closed nithinreddyy closed 1 year ago

nithinreddyy commented 2 years ago

Bug description

I installed the library and the GTK project, but it's still throwing an error like

cannot load library 'pango-1.0': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0'

Can anyone let me know the solution?

I'm using python 3.7.x version

Code snippet to reproduce the bug

from doctr.models import ocr_predictor

Error traceback

~\AppData\Roaming\Python\Python37\site-packages\cffi\api.py in _make_ffi_library(ffi, libname, flags)
    830 def _make_ffi_library(ffi, libname, flags):
    831     backend = ffi._backend
--> 832     backendlib = _load_backend_lib(backend, libname, flags)
    833     #
    834     def accessor_function(name):

~\AppData\Roaming\Python\Python37\site-packages\cffi\api.py in _load_backend_lib(backend, name, flags)
    825         if first_error is not None:
    826             msg = "%s.  Additionally, %s" % (first_error, msg)
--> 827         raise OSError(msg)
    828     return backend.load_library(path, flags)
    829 

OSError: cannot load library 'pango-1.0': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0'

Environment

I installed the library and when trying to run the code, it's throwing an error

fg-mindee commented 2 years ago

Hi @nithinreddyy :wave:

Thanks for reporting this! There are a few things missing to identify where this comes from. Would you mind sending the full traceback please (there should be multiple other lines of error traces before the ones you posted)?

Also, could you run the environment collection script and post the result over here please? :pray:

wget https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

Cheers :v:

nithinreddyy commented 2 years ago

Hi @nithinreddyy 👋

Thanks for reporting this! There are a few things missing to identify where this comes from. Would you mind sending the full traceback please (there should be multiple other lines of error traces before the ones you posted)?

Also, could you run the environment collection script and post the result over here please? 🙏

wget https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

Cheers ✌️

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_30264\4102879070.py in <module>
----> 1 from doctr.models import ocr_predictor

~\AppData\Roaming\Python\Python37\site-packages\doctr\__init__.py in <module>
----> 1 from . import datasets, io, models, transforms, utils
      2 from .file_utils import is_tf_available, is_torch_available
      3 from .version import __version__  # noqa: F401

~\AppData\Roaming\Python\Python37\site-packages\doctr\datasets\__init__.py in <module>
      1 from doctr.file_utils import is_tf_available
      2 
----> 3 from .generator import *
      4 from .cord import *
      5 from .detection import *

~\AppData\Roaming\Python\Python37\site-packages\doctr\datasets\generator\__init__.py in <module>
      2 
      3 if is_tf_available():
----> 4     from .tensorflow import *
      5 elif is_torch_available():
      6     from .pytorch import *  # type: ignore[misc]

~\AppData\Roaming\Python\Python37\site-packages\doctr\datasets\generator\tensorflow.py in <module>
      6 import tensorflow as tf
      7 
----> 8 from .base import _CharacterGenerator, _WordGenerator
      9 
     10 __all__ = ['CharacterGenerator', 'WordGenerator']

~\AppData\Roaming\Python\Python37\site-packages\doctr\datasets\generator\base.py in <module>
      9 from PIL import Image, ImageDraw
     10 
---> 11 from doctr.io.image import tensor_from_pil
     12 from doctr.utils.fonts import get_font
     13 

~\AppData\Roaming\Python\Python37\site-packages\doctr\io\__init__.py in <module>
      1 from .elements import *
----> 2 from .html import *
      3 from .image import *
      4 from .pdf import *
      5 from .reader import *

~\AppData\Roaming\Python\Python37\site-packages\doctr\io\html.py in <module>
      6 from typing import Any
      7 
----> 8 from weasyprint import HTML
      9 
     10 __all__ = ['read_html']

~\miniconda3\envs\gpu\lib\site-packages\weasyprint\__init__.py in <module>
    323 
    324 # Work around circular imports.
--> 325 from .css import preprocess_stylesheet  # noqa isort:skip
    326 from .html import (  # noqa isort:skip
    327     HTML5_UA_COUNTER_STYLE, HTML5_UA_STYLESHEET, HTML5_PH_STYLESHEET,

~\miniconda3\envs\gpu\lib\site-packages\weasyprint\css\__init__.py in <module>
     25 from ..logger import LOGGER, PROGRESS_LOGGER
     26 from ..urls import URLFetchingError, get_url_attribute, url_join
---> 27 from . import computed_values, counters, media_queries
     28 from .properties import INHERITED, INITIAL_NOT_COMPUTED, INITIAL_VALUES
     29 from .utils import get_url, remove_whitespace

~\miniconda3\envs\gpu\lib\site-packages\weasyprint\css\computed_values.py in <module>
     14 
     15 from ..logger import LOGGER
---> 16 from ..text.ffi import ffi, pango, units_to_double
     17 from ..text.line_break import Layout, first_line_metrics, line_size
     18 from ..urls import get_link_attribute

~\miniconda3\envs\gpu\lib\site-packages\weasyprint\text.py in <module>
    259                  'libgobject-2.0.dylib')
    260 pango = dlopen(ffi, 'pango-1.0', 'libpango-1.0-0', 'libpango-1.0.so.0',
--> 261                'libpango-1.0.dylib')
    262 pangocairo = dlopen(ffi, 'pangocairo-1.0', 'libpangocairo-1.0-0',
    263                     'libpangocairo-1.0.so.0', 'libpangocairo-1.0.dylib')

~\miniconda3\envs\gpu\lib\site-packages\weasyprint\text.py in dlopen(ffi, *names)
    253             pass
    254     # Re-raise the exception.
--> 255     return ffi.dlopen(names[0])  # pragma: no cover
    256 
    257 

~\AppData\Roaming\Python\Python37\site-packages\cffi\api.py in dlopen(self, name, flags)
    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)

~\AppData\Roaming\Python\Python37\site-packages\cffi\api.py in _make_ffi_library(ffi, libname, flags)
    830 def _make_ffi_library(ffi, libname, flags):
    831     backend = ffi._backend
--> 832     backendlib = _load_backend_lib(backend, libname, flags)
    833     #
    834     def accessor_function(name):

~\AppData\Roaming\Python\Python37\site-packages\cffi\api.py in _load_backend_lib(backend, name, flags)
    825         if first_error is not None:
    826             msg = "%s.  Additionally, %s" % (first_error, msg)
--> 827         raise OSError(msg)
    828     return backend.load_library(path, flags)
    829 

OSError: cannot load library 'pango-1.0': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0'

The above is the complete traceback error.
nithinreddyy commented 2 years ago

After running python collect_env.py, the below is the output

Collecting environment information...

DocTR version: N/A
TensorFlow version: 2.7.0
PyTorch version: 1.10.0+cu113 (torchvision 0.11.1+cu113)
OpenCV version: 4.5.4
OS: Microsoft Windows 10 Home Single Language
Python version: 3.7.12
Is CUDA available (TensorFlow): Yes
Is CUDA available (PyTorch): Yes
CUDA runtime version: 11.2.67
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
nithinreddyy commented 2 years ago

Hi @nithinreddyy 👋

Thanks for reporting this! There are a few things missing to identify where this comes from. Would you mind sending the full traceback please (there should be multiple other lines of error traces before the ones you posted)?

Also, could you run the environment collection script and post the result over here please? 🙏

wget https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

Cheers ✌️

It's not even showing in the installed libraries list. Below is the image

Capture
fg-mindee commented 2 years ago

Thanks for the traceback, it comes from weasyprint then :thinking: About your last message, I think I wasn't very clear: would you mind running this snippet:

wget https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

and paste the exact result of here please? :pray:

nithinreddyy commented 2 years ago

https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py

The below is the output

Collecting environment information...

DocTR version: N/A
TensorFlow version: 2.7.0
PyTorch version: 1.10.0+cu113 (torchvision 0.11.1+cu113)
OpenCV version: 4.5.4
OS: Microsoft Windows 10 Home Single Language
Python version: 3.7.12
Is CUDA available (TensorFlow): Yes
Is CUDA available (PyTorch): Yes
CUDA runtime version: 11.2.67
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect

Why it's showing as DocTR version: N/A? I already installed the library

nithinreddyy commented 2 years ago

https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py

The below is the output

Collecting environment information...

DocTR version: N/A
TensorFlow version: 2.7.0
PyTorch version: 1.10.0+cu113 (torchvision 0.11.1+cu113)
OpenCV version: 4.5.4
OS: Microsoft Windows 10 Home Single Language
Python version: 3.7.12
Is CUDA available (TensorFlow): Yes
Is CUDA available (PyTorch): Yes
CUDA runtime version: 11.2.67
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect

Why it's showing as DocTR version: N/A? I already installed the library

Can you please mail me to nithinreddy1677@gmail.com? Here i think it'll take so much time. It'd be helpful.

fg-mindee commented 2 years ago

Hi @nithinreddyy :wave:

Well it's better if we can solve your problem here since it may help others looking for a solution to that :sweat_smile:

It is indeed strange, it seems like you haven't installed docTR yet. Let's try to do this with the latest version:

pip install -e git+https://github.com/mindee/doctr.git#egg=python-doctr[tf]

or

pip install -e git+https://github.com/mindee/doctr.git#egg=python-doctr[tf]

Anyway, back to your problem, we need to get from weasyprint import HTML to work on your system because this is the source of the problem. Perhaps the best way is to check their official installation steps for Windows: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html

nithinreddyy commented 2 years ago
pip install -e git+https://github.com/mindee/doctr.git#egg=python-doctr[tf]

It's returning the same issue. Below is the image

4
fg-mindee commented 2 years ago

Oh but then the problem was not on the import, but at the installation step for sure. Have you tried my suggestion of following installation instructions?

Anyway, back to your problem, we need to get from weasyprint import HTML to work on your system because this is the source of the problem. Perhaps the best way is to check their official installation steps for Windows: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html

nithinreddyy commented 2 years ago

Oh but then the problem was not on the import, but at the installation step for sure. Have you tried my suggestion of following installation instructions?

Anyway, back to your problem, we need to get from weasyprint import HTML to work on your system because this is the source of the problem. Perhaps the best way is to check their official installation steps for Windows: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html

Yes, i tried installing weasyprint. It installed.

I ran 'python -m pip install weasyprint' this command, it worked well. Then i tried running 'python -m weasyprint --info', then it returned the error like pango...

I don't know from where it's the exact problem is.

Weasyprint is installed. Below is the image for your reference

1
fg-mindee commented 2 years ago

According to your previous traceback, the problem definitely comes from weasyprint. You installed the lib, but apparently, the installation isn't working as it should (cf. pango error). Hard for me to help, we're mostly running Linux here and I haven't been able to reproduce your error :/

Perhaps the best thing to do is to open an issue on their repo https://github.com/Kozea/WeasyPrint ?

nithinreddyy commented 2 years ago

According to your previous traceback, the problem definitely comes from weasyprint. You installed the lib, but apparently, the installation isn't working as it should (cf. pango error). Hard for me to help, we're mostly running Linux here and I haven't been able to reproduce your error :/

Perhaps the best thing to do is to open an issue on their repo https://github.com/Kozea/WeasyPrint ?

Ok

fg-mindee commented 2 years ago

Let us know if you hear from them because I'm afraid we cannot do much over here :pray: This is the type of problem we cannot solve by modifying docTR, but we can inform users on how to get around it :+1:

fg-mindee commented 2 years ago

Hi @nithinreddyy :wave:

Did you manage to get an answer to your problem? :)

nithinreddyy commented 2 years ago

Hi @nithinreddyy :wave:

Did you manage to get an answer to your problem? :)

No.

rishabhshah13 commented 2 years ago

I managed to solve this issue by the following steps, this is for windows 10, python 3.9.1

  1. Install gtk3-runtime-3.24.14-2020-02-21-ts-win64.exe version (https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases/download/2020-02-21/gtk3-runtime-3.24.14-2020-02-21-ts-win64.exe)
  2. Download harfbuzz-4.0.1 (https://github.com/harfbuzz/harfbuzz/releases/download/4.0.1/harfbuzz-win64-4.0.1.zip)
  3. Copy all content from harbuzz and paste it to GTK3-Runtime Win64\bin
fg-mindee commented 2 years ago

Thanks for reporting that @rishabhshah13 :pray: @nithinreddyy this might be worth a try perhaps?

nithinreddyy commented 2 years ago

Thanks for reporting that @rishabhshah13 :pray: @nithinreddyy this might be worth a try perhaps?

Will try and let you know.

nithinreddyy commented 2 years ago

Thanks for reporting that @rishabhshah13 🙏 @nithinreddyy this might be worth a try perhaps?

It's returning the same error.

rishabhshah13 commented 2 years ago

@nithinreddyy Install different versions of GTK3 and check which on works for you

nithinreddyy commented 2 years ago

@nithinreddyy Install different versions of GTK3 and check which on works for you

Where can i get the different versions? Please let me know if you have any idea.

rishabhshah13 commented 2 years ago

I managed to solve this issue by the following steps, this is for windows 10, python 3.9.1

  1. Install gtk3-runtime-3.24.14-2020-02-21-ts-win64.exe version (https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases/download/2020-02-21/gtk3-runtime-3.24.14-2020-02-21-ts-win64.exe)
  2. Download harfbuzz-4.0.1 (https://github.com/harfbuzz/harfbuzz/releases/download/4.0.1/harfbuzz-win64-4.0.1.zip)
  3. Copy all content from harbuzz and paste it to GTK3-Runtime Win64\bin

Download different version from here: https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases

and perform the 2 other steps

frgfm commented 2 years ago

Checking in: @nithinreddyy did you manage to solve your problem? :)

felixdittrich92 commented 2 years ago

Hi @nithinreddyy 👋 any updates ? :)

nithinreddyy commented 2 years ago

Hi @nithinreddyy 👋 any updates ? :)

No.

felixdittrich92 commented 2 years ago

Hi @nithinreddyy 👋 any updates ? :)

No.

Still not working? Then could you please try to install doctr from main branch?

nithinreddyy commented 2 years ago

Hi @nithinreddyy 👋 any updates ? :)

No.

Still not working? Then could you please try to install doctr from main branch?

Yes, will try.

felixdittrich92 commented 2 years ago

Thanks ❤️

felixdittrich92 commented 1 year ago

Should work now (with main branch) otherwise feel free to reopen :)

frgfm commented 1 year ago

@felixdittrich92 mind adding a reference to the corresponding PR? (I assume a PR has been merged because of your previous message :) )

felixdittrich92 commented 1 year ago

1031 removes the upper limit for weasyprint (where cairo is no dependency /pango version upgrade and has much more tests for Windows and MacOS) which should fix the issue

murmuruuu commented 9 months ago

Hi, I have been struggling with the same error message and figured out having GraphViz installed on Windows causes some version incompability among the external libraries from GTK+. So after uninstalling GraphViz, it worked for me. See: https://github.com/WhyNotHugo/django-afip/issues/157