10👍
Starting from Python 3.8 DLL dependencies for extension modules and DLLs loaded with ctypes
on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory()
are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution.
If you followed the installation guide from the official documentation then the following example works.
import os
os.add_dll_directory(r"C:\Program Files\GTK3-Runtime Win64\bin")
from weasyprint import HTML
HTML('https://weasyprint.org/').write_pdf('weasyprint-website.pdf')
In essence you need to call add_dll_directory()
before interacting with WeasyPrint.
5👍
I got desperate and decided to install the library gtk2 C:\Program Files (x86)\GTK2\lib\
and specify the first in the PATH list. It worked… But my OS – win 10 x64. Why the library GTK3 refused to work, I do not know.
- Django/Webpack – How to serve generated webpack bundles with webpack dev server
- How to import and run a django function at the command line
- Resize image maintaining aspect ratio AND making portrait and landscape images exact same size?
5👍
For MacOS this helped. Bascially you have to create few links.
sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib
/usr/local/lib/gobject-2.0
sudo ln -s
/opt/homebrew/opt/pango/lib/libpango-1.0.dylib
/usr/local/lib/pango-1.0
sudo ln -s
/opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib
/usr/local/lib/harfbuzz
sudo ln -s
/opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib
/usr/local/lib/fontconfig-1
sudo ln -s
/opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib
/usr/local/lib/pangoft2-1.0
https://github.com/Kozea/WeasyPrint/issues/1556#issuecomment-1097977671
- Merge/join lists of dictionaries based on a common value in Python
- Django Create View Image Upload
- What is the difference between syncdb and migrate?
- <django.db.models.fields.related.RelatedManager object at 0x7ff4e003d1d0> is not JSON serializable
1👍
For me this was about env variables not set correctly.
I had to add GTK3 as a System env variable in Windows for my project to work (Windows 10).
- Celery immediately exceeds memory on Heroku
- Django-Storages S3 with minio as backend
- Hide password field in GET but not POST in Django REST Framework where depth=1 in serializer
1👍
Solution that worked for me:
- Following
weasyprint
usage on Windows, download and install GTK. - Add GTK at start of python (in this case
python manage.py runserver
):
# insert the GTK3 Runtime folder at the beginning. Can be bin or lib, depending on path you choose while installing.
GTK_FOLDER = r'C:\Program Files\GTK3-Runtime Win64\bin'
os.environ['PATH'] = GTK_FOLDER + os.pathsep + os.environ.get('PATH', '')
- How to format django template in Sublime Text
- Django: Display a custom error message for admin validation error
- Got AttributeError when attempting to get a value for field on serializer
- Django-registration: how do I check whether the user is logged in before displaying a page
- Specify order of columns in SELECT with UNION using Django ORM
0👍
I made a django website for windows 10 with the weasyprint library. Also installed GTK+ for Windows Runtime Environment (version 3). The same errors were thrown.
I tried to swap paths in path, updated windows to 11, but it didn’t help.
Then i pasted ‘sitecustomize.py’ like Tontyna https://github.com/Kozea/WeasyPrint/issues/971#issuecomment-544195744 to the virtual environment folder ‘/Lib/site-packages’,
another error occurred: Fontconfig error: Cannot load default config file.
It turned out that the ‘C:\Users<User>\anaconda3\fontconfig.dll’ library is being loaded.
In the file ‘sitecustomize.py’ I changed the line:
os.environ['PATH'] = GTK_FOLDER + os.pathsep + os.environ.get('PATH', '')
to the line:
os.environ['PATH'] = GTK_FOLDER
and it WORKS
- Django pre_save signal does not work
- Django cache framework. What is the difference between TIMEOUT and CACHE_MIDDLEWARE_SECONDS?
- 'Suspicious Operation: Attempted access to "" denied' while loading static files
- Why is gunicorn_django not recommended anymore?