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

[Windows] ffi.dlopen fails if lib path contains space #158

Open
mahmoudajawad opened this issue May 23, 2020 · 2 comments
Open

[Windows] ffi.dlopen fails if lib path contains space #158

mahmoudajawad opened this issue May 23, 2020 · 2 comments
Labels

Comments

@mahmoudajawad
Copy link

mahmoudajawad commented May 23, 2020

Occasionally, when I'm refreshing Python installation on Windows 10, I end up with issues attempting to get weasyprint to work, and it's only that some random step that resolves the issue and I just overlook what happened and continue my day. Today however, I wanted to document what has happened to me in order to make sure I know exactly what has happened and how to resolve the issue in the future. I've done this:

  1. Installed Python 3.8.3 from Windows Store (Not from Python website).
  2. Installed GTK3 (64-bit) binaries from repo mentioned in weasyprint docs.
  3. Installed weasyprint.
  4. Ran python -c 'import weasyprint'.
  5. Got:
cannot load library 'C:\Program Files\GTK3-Runtime Win64\bin\libcairo-2.dll': error 0x7e
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e

To understand what's going on, I added a breakpoint at line 45 for file __init__.py which is one step before raising OSError.

Printing exceptions from the breakpoint gave the following message:

['no library called "cairo" was found', OSError("cannot load library 'C:\\Program Files\\GTK3-Runtime Win64\\bin\\libcairo-2.dll': error 0x7e"), OSError("cannot load library 'libcairo.so': error 0x7e"), OSError("cannot load library 'libcairo.2.dylib': error 0x7e"), OSError("cannot load library 'libcairo-2.dll': error 0x7e")]

I could be wrong, but isn't this asserting ffi.dlopen is failing because it's not correctly escaping the spaces in the path to load the lib?

@Nazieh
Copy link

Nazieh commented May 28, 2020

Hala mahmoudajawad,

You are right the problem is with spaces in the directory name.

Just download the gtk+ bundle from here,
unzip the file into a directory with no spaces, ( C:\gtk ) for example,
finally just add the bin directory of the folder you unzipped into your path variable.

Not super elegant, but works.

@mahmoudajawad
Copy link
Author

@Nazieh, thanks for your reply. Yes, this works. I can confirm. I'm hoping the bug itself can be resolved for others as well.

@liZe liZe added the bug label Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants