Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.23k stars 686 forks source link

Import fails with "cannot load library 'pangoft2-1.0-0': error 0x7e" on windows, even after setting WEASYPRINT_DLL_DIRECTORIES env var #2198

Closed Gilthans closed 4 months ago

Gilthans commented 4 months ago

Hey there, I've installed weasyprint using conda in a separate environment. It seems to have installed all the dependencies (at least I can find them), but importing the library via python fails with:

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

After following the issues, I tried setting the environment variable, and verified it was set:

    print(os.environ['WEASYPRINT_DLL_DIRECTORIES'])

    from weasyprint import CSS, HTML
    from weasyprint.text.fonts import FontConfiguration

I get this:

E:\msys64\mingw64\bin

Which appears to be correct (at least, it contains a libpangoft2-1.0-0.dll file). However, the install still fails. What else should I be checking here?

liZe commented 4 months ago

Hi!

You should not mix MSYS2 and Conda. Use only one of them, but not both.

If you use Conda, installing Conda’s WeasyPrint should just work. If it doesn’t, then it’s a problem with your Conda installation, and there’s not much we can do for you here (I’ve never used Conda myself).

If you use MSYS2 with the default install folder, it should work out of the box with Microsoft Store’s Python. If you install MSYS2 elsewhere, you can set the WEASYPRINT_DLL_DIRECTORIES environment variable (looks like it’s what you did). If you use another version of Python, you may get other problems for reasons I don’t understand.

Gilthans commented 4 months ago

I've tried removing my venv folder and reinstalling from scratch, without setting the environment variable, but I still get the same issue...

liZe commented 4 months ago

I've tried removing my venv folder and reinstalling from scratch, without setting the environment variable, but I still get the same issue...

Let’s carefully follow the steps proposed by the documentation:

If anything goes wrong during these steps, please share what went wrong, we’ll try to find a solution.

When everything works, you’ll be free to try a different way to install WeasyPrint (change MSYS2 path, install Python from elsewhere, use Conda…) We won’t be able to help you for this, but at least you’ll be able to go step by step and understand what’s exactly going on.

liZe commented 4 months ago

@Gilthans Did you find the time to try these steps?

Gilthans commented 4 months ago

Unfortunately in my case if I can't get it working in a conda environment this isn't relevant (it would require rewriting our deployment). I did try installing using pip inside the conda environment, but still did not work. Even after setting the environment variable, which appears to point to the right directory, it can't find the lib

liZe commented 4 months ago

Unfortunately in my case if I can't get it working in a conda environment this isn't relevant

If you want to use WeasyPrint with Conda, you don’t need MSYS2 at all. WeasyPrint is already packaged for Conda, with all its dependencies.

Gilthans commented 4 months ago

I've tried installing the conda package, but it still cannot find the dependency, even after recreating the environment from scratch

liZe commented 4 months ago

I've tried installing the conda package, but it still cannot find the dependency, even after recreating the environment from scratch

Hmm… The Conda packages seems to be downloaded regularly, I suppose that it works for some users. If it doesn’t work for you, maybe you’ll get more useful help by opening an issue on Conda’s bug tracker?

NormanT7 commented 4 months ago

I've run into the same issue. When I install the pango conda-forge on Windows, there aren't any pangoft2 libraries included with it. I see pango-1.0-0, pangocairo-1.0-0, and pangowin32-1.0-0 dlls but no pangoft2 anything.

liZe commented 4 months ago

I've run into the same issue. When I install the pango conda-forge on Windows, there aren't any pangoft2 libraries included with it. I see pango-1.0-0, pangocairo-1.0-0, and pangowin32-1.0-0 dlls but no pangoft2 anything.

Looks like it’s a problem with Conda’s package. Let’s continue the discussion in https://github.com/conda-forge/weasyprint-feedstock/issues/31.