Kozea / WeasyPrint

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

"The procedure entry point (...) could not be located" on windows #2201

Closed reasv closed 4 months ago

reasv commented 4 months ago

I was having the same issue as https://github.com/Kozea/WeasyPrint/issues/2198 and decided to follow your instructions at https://github.com/Kozea/WeasyPrint/issues/2198#issuecomment-2213227564 So I uninstalled every python distribution I have including conda from my system before installing python 3.12 from the windows store.

Now I get a different error: e2sAbDcWcv This happens on import, yes it shows up as a window. There's multiple, one for each library.

liZe commented 4 months ago

Hi!

Did you try to restart your computer? It can help if you installed/uninstalled some packages.

Otherwise, does this libgobject-2.0-0.dll file still exists on your system?

reasv commented 4 months ago

The file does exist image Restarting did not solve the problem. There's a similar error for each of the dlls including harfbuzz. It seems to be loading them but not finding these procedure entry points.

reasv commented 4 months ago

I found out that after dismissing these (4-5!) error messages, weasyprint works in interactive python. I was able to do this

Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import weasyprint
>>>
(process:25672): GLib-GIO-WARNING **: 08:40:38.818: Unexpectedly, UWP app `Microsoft.OutlookForWindows_1.2024.111.100_x64__8wekyb3d8bbwe' (AUMId `Microsoft.OutlookForWindows_8wekyb3d8bbwe!Microsoft.OutlookforWindows') supports 1 extensions but has no verbs

(process:25672): GLib-GIO-WARNING **: 08:40:38.912: Unexpectedly, UWP app `Microsoft.ScreenSketch_11.2405.32.0_x64__8wekyb3d8bbwe' (AUMId `Microsoft.ScreenSketch_8wekyb3d8bbwe!App') supports 29 extensions but has no verbs

(process:25672): GLib-GIO-WARNING **: 08:40:38.958: Unexpectedly, UWP app `Clipchamp.Clipchamp_3.1.10920.0_neutral__yxz26nhyzhsrt' (AUMId `Clipchamp.Clipchamp_yxz26nhyzhsrt!App') supports 41 extensions but has no verbs

>>> from weasyprint import HTML
>>> HTML('https://weasyprint.org')
<weasyprint.HTML object at 0x0000024B6688DE50>
>>> html = HTML('https://weasyprint.org')
>>> html.write_pdf("test.pdf")
>>>

And get a working PDF with the expected content.

But these error windows, along with those console errors, show up every time I import weasyprint and that's a problem and probably not something that should happen. image

liZe commented 4 months ago

I found out that after dismissing these (4-5!) error messages, weasyprint works in interactive python.

Wow, that’s another problem on Windows I’ve never seen before!

I really think that you have multiple versions of these libraries installed on your computer. Many people get this error with many apps, that’s just another DLL hell problem.

https://stackoverflow.com/questions/20854074/the-procedure-entry-point-could-not-be-found

About the GLib warning, it looks like it’s a common message too: https://github.com/3b1b/manim/issues/1556. Uninstalling or reinstalling the concerned apps seems to fix the problem.

These two problems come from interactions with other programs installed on your system. As I’ve not used Windows for a very long time, I won’t be able to help you with that, you’ll probably get more help from Windows masters on StackOverflow.

If you want to avoid these problems, you can also try to use WSL, or the Windows executable we provide.

reasv commented 4 months ago

you can also try to use WSL, or the Windows executable we provide.

Unfortunately both of these choices aren't realistic for my use case. The executable works just fine with no errors, but the reason I am even trying to get weasyprint to work is I am using a different library that calls weasyprint. Using WSL would work but I want windows users to be able to run my project without needing WSL. Once I solve this problem on my machine I might just build an installer to try and make dependencies work.

I can say that I did have GTK3-runtime installed, I found out by searching the filename with Everything. Now it seems there's only one version of the library in PATH: image

However, after creating the new venv, and installing weasyprint again, I now get the original error back:

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'

But the mingw directory with the library is in PATH. I verified it.

So I tried this:

>>> print(ctypes.util.find_library('gobject-2.0-0'))
None
>>> print(ctypes.util.find_library('libgobject-2.0-0'))
C:\msys64\mingw64\bin\libgobject-2.0-0.dll
>>> ctypes.CDLL(ctypes.util.find_library('libgobject-2.0-0'))
<CDLL 'C:\msys64\mingw64\bin\libgobject-2.0-0.dll', handle 7ff95ded0000 at 0x148eaa8cf80>
>>>

It works when loaded as libgobject, but not as gobject. It seems on msys2 the name is different? What could this mean?

I tried duplicating libgobject-2.0-0.dll and renaming the copy to gobject-2.0-0.dll Now this works:

>>> ctypes.util.find_library('gobject-2.0-0')
'C:\\msys64\\mingw64\\bin\\gobject-2.0-0.dll'
>>> ctypes.CDLL(ctypes.util.find_library('gobject-2.0-0'))
<CDLL 'C:\msys64\mingw64\bin\gobject-2.0-0.dll', handle 7ff94ccc0000 at 0x148eaa8cd10>

Now, when trying to import weasyprint, it no longer complains about gobject, instead complaining about pango. So I decided to copy and rename all of the dlls to see what would happen

I copied the entire bin directory from mingw64, created bin2 and renamed all the lib.dll files into .dll and put bin2 in PATH

I now get this error

OSError: cannot load library 'C:\msys64\mingw64\bin2\gobject-2.0-0.dll': error 0x7e

I think this is because it's no longer finding its own dependencies since I changed the filenames.

So I tried one last thing, copying all DLLs from bin2 to bin and deleting bin2.

OSError: cannot load library 'C:\msys64\mingw64\bin\gobject-2.0-0.dll': error 0x7e

I'm out of ideas.

liZe commented 4 months ago

I can say that I did have GTK3-runtime installed, I found out by searching the filename with Everything.

OK, that’s your problem, you have 2 different versions of the libraries installed.

Now it seems there's only one version of the library in PATH:

Python doesn’t use PATH anymore to find libraries. Instead, we now have to declare paths where to look for libraries, as it’s done here:

https://github.com/Kozea/WeasyPrint/blob/c345629b33715b6d7230daeec33a252e39fdce34/weasyprint/text/ffi.py#L475-L481

The problem may come the fact that you have both MSYS2 and GTK3 libraries installed, as WeasyPrint looks in these two folders by default. Maybe setting WEASYPRINT_DLL_DIRECTORIES to C:\msys64\mingw64\bin only will fix the problem.

It works when loaded as libgobject, but not as gobject. It seems on msys2 the name is different? What could this mean?

I tried duplicating libgobject-2.0-0.dll and renaming the copy to gobject-2.0-0.dll

Please don’t do this, you don’t have to rename the files. WeasyPrint already tries different names (including libgobject-2.0-0.dll).

reasv commented 4 months ago

OK, that’s your problem, you have 2 different versions of the libraries installed.

I had uninstalled GTK3-runtime already. It's gone, the DLLs too. Uninstalled MSYS2. Deleted venv. Made sure all files are gone. No more gobject DLLs in path. Reinstalled MSYS2. Ran pacman command again to install pango.

Created new venv with microsoft store python (checked with where python) Activated venv. installed weasyprint.

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'

Still got this error, despite deleting GTK-3 runtime and all its DLLs.

>>> os.environ["WEASYPRINT_DLL_DIRECTORIES"] = r"C:\msys64\mingw64\bin"
>>> import weasyprint
>>>

Ok, this finally worked. No errors. Now I need to get it to all work with poetry but it seems my issue is solved.

reasv commented 4 months ago

Thanks for your help. It seems in the end a combination of different issues caused my problems