django OSError: no library called "cairo" was found on windows
Asked Answered
W

9

23

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
Wilhelmina answered 25/12, 2019 at 19:46 Comment(6)
Please can you provide more details eg Version of Djano, version of Windows.Trumantrumann
The output of pip freeze would be useful here. How are you running your Django project? with manage.py?Bale
Can we get the operation system as well as its version?Conchita
Are you using weasyprint in your project?Inapt
I am facing the same issue ,i am using django-weasyprint.Bevy
Please check my answerInapt
I
10

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
Inapt answered 27/12, 2019 at 5:20 Comment(5)
I am still getting this error even after installing the GTKFlann
Do not forget to add the installed GTK+ lib to your system path, and restart your IDE so that the changes take effect.Catabolism
@Catabolism agree.Inapt
@Catabolism how do i add them to the path?Tenaculum
Follow the instructions here: "gisaxs.com/index.php/View.gtk_installation" and replace "C:\GTK\bin" with the actual path where you installed the GTK package on your drive.Catabolism
E
13

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!
Erhart answered 13/7, 2020 at 1:36 Comment(1)
working download link here downloads.sk1project.net/uc2/MS_Windows/…Diamagnetism
I
10

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
Inapt answered 27/12, 2019 at 5:20 Comment(5)
I am still getting this error even after installing the GTKFlann
Do not forget to add the installed GTK+ lib to your system path, and restart your IDE so that the changes take effect.Catabolism
@Catabolism agree.Inapt
@Catabolism how do i add them to the path?Tenaculum
Follow the instructions here: "gisaxs.com/index.php/View.gtk_installation" and replace "C:\GTK\bin" with the actual path where you installed the GTK package on your drive.Catabolism
K
4

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

Kamalakamaria answered 4/8, 2020 at 20:31 Comment(1)
OMG this is what fixed for me after nothing else. Thanks!Kirwin
A
2

See the solution here:

https://www.programmersought.com/article/47674569357/

You will need to add a path if not added after installations:

C:\Program Files\GTK3-Runtime Win64\bin

I have been solving it many times this way.

Autry answered 12/7, 2021 at 10:21 Comment(0)
M
2

If you are using a lightweight Linux Docker Image, it may not include GTK as said above, then, you can include it by adding in your Dockerfile

RUN apt-get update -y
RUN apt-get install python3-cffi python3-brotli libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 libgtk-3-dev gcc -y

Where all those packages are recommended to be installed by weasyprint and GCC has the GTK.

Mansell answered 30/12, 2021 at 15:36 Comment(0)
I
2

Try this: https://cairocffi.readthedocs.io/en/stable/overview.html#installing-cairo-on-windows

And maybe this will work to: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycairo

Best option is instal cairocffi trough pipwin

pip install pipwin

pipwin install cairocffi
Imparipinnate answered 3/1, 2023 at 19:47 Comment(0)
B
1

Ok I figure this out. you can have a 64 bit version of python that doesn't work. What I have found to work and this could change is the installing the 64 bit version of python from python's website, not from the Microsoft store!

  1. remove any version of python you have installed
  2. download https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe
  3. install
  4. download and install https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases
    1. exact link is https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases/download/2021-04-29/gtk3-runtime-3.24.29-2021-04-29-ts-win64.exe
    2. note that link is from https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#windows
  5. add bin folder from that (sorry it was somebody else's machine, I use Ubuntu) in your environment path.
  6. run through the first steps on weasyprint and you should be good to go!
Broadnax answered 24/9, 2021 at 19:35 Comment(1)
Yep, that did the trick! Seems to be an issue with Python installed from the Microsoft Store. I took Python 3.10.1 and it worked for me. Maybe just don’t put a direct link to a specific Python installer, just point to the official website like you did for the GTK installer. Also note that this way of installing Python does not provide the python3 command-line alias. Just use python instead.Rosemaryrosemond
A
0

Might be a bit late, but I just encoutered the same issue and: Start here: https://weasyprint.readthedocs.io/en/stable/install.html#windows. Where you will find the links for the GTK Pack that contains the required DLLs.

In my case, I have a 64bit Python, so i use: "Download and run the latest gtk3-runtime-x.x.x-x-x-x-ts-win64.exe"

I did not change the installation directory

Once the installation is completed. I added the path to my variable paths.

I restarted the terminal, made sure I could locate the DLLs with : WHERE libcairo-2.dll. This retured C:\Program Files\GTK3-Runtime Win64\bin\libcairo-2.dll

Then I run python -m weasyprint http://weasyprint.org weasyprint.pdf and got a few WARNINGs but they are just warnings :)

Anti answered 1/7, 2021 at 5:10 Comment(0)
M
0

I have faced same error as well

I haved installed gtk as followed as gtk install in windows

Nothing worked

After that :

python -m pip install pycairo

solved the problem for me

Metaxylem answered 18/8, 2021 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.