简体   繁体   中英

Install needed libraries for Weasyprint on pipenv (Windows environment)

In order to start generating documents with Weasyprint I installed it on my Windows machine following these instructions:
https://weasyprint.readthedocs.io/en/stable/install.html#step-5-run-weasyprint

On my computer it works but I have a Django project where I want to integrate this library and I use pipenv.
How to install the necessary libraries even in the virtual environment?
I tried setting the path for the pycairo package into the Pipfile like

pycairo= {path= "C:/Program Files/GTK3-Runtime Win64/bin/"}

but still it throws the error:

OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2 / cairo.so.2

I have 64bit Windows machine and this is the Pipfile:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pylint = "*"

[packages]
django = "*"
mysql = "*"
ipython = "*"
django-webpack = "*"
django-webpack-loader = "*"
django-livereload-server = "*"
pylint = "*"
reportlab = "*"
weasyprint = "*"
django-weasyprint = "*"
pycairo= {path= "C:/Program Files/GTK3-Runtime Win64/bin/"}
cairocffi = "*"

[requires]
python_version = "3.7"

You need install 'GTK+ 64 Bit Installer' path in this local:

C:\\msys2

Source: WeasyPrint Github

I came across this error as well and followed every step mentioned in the Weasyprint docs for the installation. I was using PowerShell as my default terminal and pipenv . First I tried using the command import weasyprint inside python shell in my virtualenv, but it always returned the cairo, dlopen() etc error.

What worked for me was switching to cmd. Switched and used the same commands and now it's executing perfectly.

Also, in my pipfile, for weasyprint, which is enough to generate a report in django, I only have weasyprint installed. In the question, if it is still relevant for someone, the libraries reportlab , django-weasyprint , pycairo and cairocffi can be safely removed/uninstalled from pipenv.

Please type the following command:

  • WHERE libcairo-2.dll
  • you should be getting 'C:\\msys2\\mingw64\\bin\\libcairo-2.dll'
  • then open your cmd and type the following.

  • SET PROPER_GTK_FOLDER=

  • SET PATH=%PROPER_GTK_FOLDER%;%PATH%

Please follow the documentation it has everything to run on windows. It worked for me it i hope it will work for you enter link description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM