Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create PDF with weasyprint 53.3 installed from conda on Windows #1472

Closed
m-ad opened this issue Oct 14, 2021 · 13 comments
Closed

Unable to create PDF with weasyprint 53.3 installed from conda on Windows #1472

m-ad opened this issue Oct 14, 2021 · 13 comments

Comments

@m-ad
Copy link

m-ad commented Oct 14, 2021

Problem description

This minimal example fails to produce a PDF file with weasyprint 53.3 and 53.2:

import weasyprint
html = weasyprint.HTML(string="test")
html.write_pdf("test.pdf")

Note: The code runs fine and produces a PDF in weasyprint 52.5.

I also increased the log level of the weasyprint logger, this is the output:

Step 1 - Fetching and parsing HTML - HTML string
Step 3 - Applying CSS
Step 4 - Creating formatting structure
Step 5 - Creating layout - Page 1

Process finished with exit code -1073741819 (0xC0000005)

Environment

Windows 10 Enterprise, 64 Bit

GTK 3 is the current gtk3-runtime-3.24.29-2021-04-29-ts-win64 from here.

I set up a fresh conda environment (Python 3.9.7) in Pycharm 2021.2.2 for this test and only installed weasyprint.

Output of conda env export:

name: test_weasy
channels:
  - anaconda
  - defaults
  - conda-forge
dependencies:
  - brotli=1.0.9=ha925a31_2
  - ca-certificates=2020.10.14=0
  - cairo=1.16.0=hb19e0ff_1008
  - certifi=2021.10.8=py39haa95532_0
  - cffi=1.14.6=py39h2bbff1b_0
  - cssselect2=0.2.1=pyh9f0ad1d_1
  - font-ttf-dejavu-sans-mono=2.37=h6964260_0
  - font-ttf-inconsolata=2.001=hcb22688_0
  - font-ttf-source-code-pro=2.030=h7457263_0
  - font-ttf-ubuntu=0.83=h8b1ccd4_0
  - fontconfig=2.13.1=h1989441_1005
  - fonts-anaconda=1=h8fa9717_0
  - fonts-conda-ecosystem=1=hd3eb1b0_0
  - fonttools=4.25.0=pyhd3eb1b0_0
  - freetype=2.10.4=hd328e21_0
  - fribidi=1.0.10=h62dcd97_0
  - gettext=0.19.8.1=ha2e2712_1008
  - glib=2.68.4=h0e60522_1
  - glib-tools=2.68.4=h0e60522_1
  - graphite2=1.3.13=1000
  - harfbuzz=3.0.0=hc601d6f_1
  - html5lib=1.1=py_0
  - icu=68.1=h6c2663c_0
  - jpeg=9b=vc14h4d7706e_1
  - libffi=3.4.2=hd77b12b_0
  - libglib=2.68.4=h3be07f2_1
  - libiconv=1.16=he774522_0
  - libpng=1.6.37=h2a8f88b_0
  - libtiff=4.1.0=h56a325e_1
  - libxml2=2.9.10=hb89e7f3_3
  - lz4-c=1.9.2=hf4a77e7_3
  - munkres=1.1.4=py_0
  - olefile=0.46=py_0
  - openssl=1.1.1l=h2bbff1b_0
  - pango=1.48.10=h33e4779_2
  - pcre=8.45=hd77b12b_0
  - pillow=8.3.1=py39h4fa10fc_0
  - pip=21.2.4=py39haa95532_0
  - pixman=0.40.0=he774522_0
  - pycparser=2.20=py_2
  - pydyf=0.1.1=pyhd8ed1ab_0
  - pyphen=0.11.0=pyhd8ed1ab_0
  - python=3.9.7=h6244533_1
  - setuptools=58.0.4=py39haa95532_0
  - six=1.15.0=py_0
  - sqlite=3.36.0=h2bbff1b_0
  - tinycss2=1.1.0=pyhd8ed1ab_0
  - tk=8.6.10=he774522_0
  - tzdata=2020b=h7b6447c_0
  - ucrt=10.0.20348.0=h57928b3_0
  - vc=14.2=h21ff451_1
  - vs2015_runtime=14.29.30037=h902a5da_5
  - weasyprint=53.3=pyhd8ed1ab_0
  - webencodings=0.5.1=py39haa95532_1
  - wheel=0.35.1=py_0
  - wincertstore=0.2=py39haa95532_2
  - xz=5.2.5=h62dcd97_0
  - zlib=1.2.11=vc14h1cdd9ab_1
  - zstd=1.4.4=ha9fde0e_3
@liZe
Copy link
Member

liZe commented Oct 14, 2021

Hello!

If you use Conda, please don’t install GTK! Conda already has all the dependencies needed for WeasyPrint.

Could you please tell us what you get when GTK is not installed?

@m-ad
Copy link
Author

m-ad commented Oct 14, 2021

If you use Conda, please don’t install GTK! Conda already has all the dependencies needed for WeasyPrint.

That's interesting, I did not know that. That appears to be a change from 52 to 53, correct (see below)?

Could you please tell us what you get when GTK is not installed?

I did not uninstall GTK but changed its directory name to "hide" it. Now I get a PDF. However, there is now a pango error which crashes the script:

C:\Users\mad\Miniconda3\envs\test_weasy\lib\site-packages\weasyprint\text\fonts.py:66: UserWarning: FontConfig cannot load default config file. Expect ugly output.
  warnings.warn(
Step 1 - Fetching and parsing HTML - HTML string
Fontconfig error: Cannot load default config file
Step 3 - Applying CSS
Step 4 - Creating formatting structure
Step 5 - Creating layout - Page 1
Step 6 - Creating PDF

(process:8968): Pango-CRITICAL **: 14:07:15.466: pango_font_get_hb_font: assertion 'PANGO_IS_FONT (font)' failed

Process finished with exit code -1073741819 (0xC0000005)

If I revert to weasyprint 52.5 I get

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

which is what I'm used to when there is no GTK installation on the PATH. So it appears to me that 52.x requires a GTK installation while 53.x does not.

I would suggest adding that information to the documentation's First Steps section.

@liZe
Copy link
Member

liZe commented Oct 14, 2021

That's interesting, I did not know that. That appears to be a change from 52 to 53, correct (see below)?

So it appears to me that 52.x requires a GTK installation while 53.x does not.

No, that didn’t change.

If you install WeasyPrint using Conda’s package, all the needed libraries (pango, fontconfig…) are already installed as dependencies you don’t need to install GTK.

If you install WeasyPrint using pip, you have to install the needed libraries by installing GTK.

However, there is now a pango error which crashes the script:

Well, maybe there’s a bug in Conda’s Fontconfig package. Unfortunately, we don’t have a Windows computer to test :/. Maybe you could try to report a bug and see if people can reproduce.

I would suggest adding that information to the documentation's First Steps section.

Installing on Windows is a mess. We’ve tried many, many, many things to make this documentation better, but it’s never enough. As we don’t have any Windows computer at home, it’s definitely hard to test.

What you can do is to try a fresh install, without Conda, following the documentation (and thus using GTK).

@m-ad
Copy link
Author

m-ad commented Oct 14, 2021

Thanks for your help and information! I guess I will stick with 52.5 for a bit longer ;)

I checked my conda installation and found the fontconfig files. They are from fontconfig 2.13.1 (consistent with the most current version at conda-forge). My local GTK3 installation (from here) has fontconfig 2.13.93, so much more recent. Maybe the pango bug was fixed in between versions.

So the main issue is likely that the conda version of fontconfig should be updatd.

@m-ad m-ad changed the title Unable to create PDF with weasyprint 53.3 Unable to create PDF with weasyprint 53.3 installed from conda on Windows Oct 14, 2021
@liZe
Copy link
Member

liZe commented Oct 15, 2021

So the main issue is likely that the conda version of fontconfig should be updatd.

We really have to fix #1435 and see if it fixes all the Windows problems that have been reported during the last months.

@liZe
Copy link
Member

liZe commented Jan 3, 2022

Now that #1435 is fixed, this problem should be solved.

Note that there’s currently an unrelated bug in Conda’s fontconfig: conda-forge/fontconfig-feedstock#49

@liZe liZe closed this as completed Jan 3, 2022
@UGuntupalli
Copy link

UGuntupalli commented Jan 11, 2022

@liZe,

The error with fontconfig-1 is resulting in an error in the installation of WeasyPrint using Anaconda on Windows.

I tried to install a new virtual environment with Python 3.8 as well Python 3.9.7 and in both cases WeasyPrint failed to load.
While the installation happens uneventfully, eventually attempting to import WeasyPrint into a script fails.

OSError: ctypes.util.find_library() did not manage to locate a library called 'fontconfig-1'

Do you have a temporary alternative to this problem ?

@liZe
Copy link
Member

liZe commented Jan 12, 2022

OSError: ctypes.util.find_library() did not manage to locate a library called 'fontconfig-1'

That’s a bug of Conda’s Fontconfig.

Do you have a temporary alternative to this problem ?

The easiest way now is to follow the official install steps instead of using Anaconda. Otherwise, you can ask Conda’s packagers how you can help them to fix Fontconfig’s package.

@UGuntupalli
Copy link

@liZe,

Trying to follow the the official install steps doesn't really help. Here are the steps I followed and the error we get:

  1. Install GTK 3.0 using the latest installer provided here
  2. Create a new project
  3. Create a new virtual environment using venv and Python 3.8
  4. Install weasyprint

Attempting to import weasyprint results in an OSError:

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

@liZe
Copy link
Member

liZe commented Jan 12, 2022

OSError: cannot load library 'gobject-2.0.0'

This bug is #1435, you should use version 54.0 instead of 53.3. If you installed GTK in the default folder proposed by the installer, it will work out of the box.

@UGuntupalli
Copy link

We get the same error both with v54.0 and v53.3

@ajsmack
Copy link

ajsmack commented Jan 18, 2022

@liZe,

  1. I have a new project
  2. Create a new virtual environment using venv and Python 3.8
  3. Install GTK 3.0 using the latest installer
  4. Install weasyprint==53.3

File "C:\Users\Ajay\anaconda3\lib\site-packages\weasyprint\__init__.py", line 322, in <module> from .css import preprocess_stylesheet # noqa isort:skip File "C:\Users\Ajay\anaconda3\lib\site-packages\weasyprint\css\__init__.py", line 27, in <module> from . import computed_values, counters, media_queries File "C:\Users\Ajay\anaconda3\lib\site-packages\weasyprint\css\computed_values.py", line 16, in <module> from ..text.ffi import ffi, pango, units_to_double File "C:\Users\Ajay\anaconda3\lib\site-packages\weasyprint\text\ffi.py", line 386, in <module> harfbuzz = _dlopen( File "C:\Users\Ajay\anaconda3\lib\site-packages\weasyprint\text\ffi.py", line 377, in _dlopen return ffi.dlopen(names[0]) # pragma: no cover File "C:\Users\Ajay\AppData\Roaming\Python\Python38\site-packages\cffi\api.py", line 150, in dlopen lib, function_cache = _make_ffi_library(self, name, flags) File "C:\Users\Ajay\AppData\Roaming\Python\Python38\site-packages\cffi\api.py", line 832, in _make_ffi_library backendlib = _load_backend_lib(backend, libname, flags) File "C:\Users\Ajay\AppData\Roaming\Python\Python38\site-packages\cffi\api.py", line 827, in _load_backend_lib raise OSError(msg) OSError: ctypes.util.find_library() did not manage to locate a library called 'harfbuzz'

I got this error please help me solve this error

@liZe
Copy link
Member

liZe commented Jan 18, 2022

I got this error please help me solve this error

@ajsmack Please try version 54 and see if it fixes your problem.

We get the same error both with v54.0 and v53.3

@UGuntupalli If you don’t use Anaconda at all (even for Python), install GTK in its default install folder, use WeasyPrint 54.0 with Python 3.8 or more recent, it should just work. 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants