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

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 opened this issue Jul 7, 2024 · 10 comments

Comments

@Gilthans
Copy link

Gilthans commented Jul 7, 2024

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
Copy link
Member

liZe commented Jul 7, 2024

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
Copy link
Author

Gilthans commented Jul 7, 2024

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

@liZe
Copy link
Member

liZe commented Jul 8, 2024

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:

  • Check that you have Window 10 or 11, 64 bit installed.
  • Install Python with Microsoft Store (not from python.org), and check that where python3 gives the correct path.
  • Install MSYS2 in the default installation folder, launch pacman -S mingw-w64-x86_64-pango and check that you have everything installed in C:\msys64\mingw64\bin.
  • Create a virtual environment with python3 -m venv venv in a basic shell (not Powershell), activate it with venv\Scripts\activate.
  • Install WeasyPrint with pip install weasyprint.
  • Launch python3 and type import weasyprint.

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
Copy link
Member

liZe commented Jul 12, 2024

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

@Gilthans
Copy link
Author

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
Copy link
Member

liZe commented Jul 13, 2024

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
Copy link
Author

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

@liZe
Copy link
Member

liZe commented Jul 13, 2024

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
Copy link

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
Copy link
Member

liZe commented Jul 16, 2024

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 conda-forge/weasyprint-feedstock#31.

@liZe liZe closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2024
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

3 participants