django OSError: no library called “cairo” was found on windows

流过昼夜 提交于 2020-08-05 05:27:30

问题


When I run the Django server, I see this problem !!

OSError: no library called "cairo" was found

no library called "libcairo-2" was found

cannot load library 'libcairo.so': error 0x7e

cannot load library 'libcairo.2.dylib': error 0x

cannot load library 'libcairo-2.dll': error 0x7e

回答1:


WeasyPrint needs the Pango, cairo and GDK-PixBuf libraries. They are part of GTK+ (formerly known as GIMP Toolkit), and must be installed separately.

After installing GTK+ libraries, do :

python -m weasyprint http://weasyprint.org weasyprint.pdf



回答2:


Installing GTK+ didn't work for me. I solved this problem using UniConverter2.0. My environments is

  • Python 3.7
  • Windows 10 x64
  1. Install uniconvertor-2.0rc4-win64_headless.msi,
  2. Find the "dll" sub-directory under the UniConverter installation path.(In my case, C:\Program Files\UniConvertor-2.0rc4\dlls)
  3. Add this "dll" path to the system path.
  4. Close VSCode and reopen the project.
  5. Try to run the server again. Enjoy!



回答3:


Starting from Python 3.8, dll's need to be added separately. Added GTK+, MSYS2, Visual Studio C Compiler and Uniconverter. But, nothing seemed to work. Finally, got it working after putting the script for calling add_dll_directory.

import os

def set_dll_search_path():
   # Python 3.8 no longer searches for DLLs in PATH, so we have to add
   # everything in PATH manually. Note that unlike PATH add_dll_directory
   # has no defined order, so if there are two cairo DLLs in PATH we
   # might get a random one.
   if os.name != "nt" or not hasattr(os, "add_dll_directory"):
       return
   for p in os.environ.get("PATH", "").split(os.pathsep):
       try:
           os.add_dll_directory(p)
       except OSError:
           pass


set_dll_search_path()

Source: PyCairo Windows Python3.8 Import Issue



来源:https://stackoverflow.com/questions/59481394/django-oserror-no-library-called-cairo-was-found-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!