[Solved] MacBook (M1 chip) OSError: no library called cairo/pango was found

[Solved] MacBook (M1 chip) OSError: no library called cairo/pango was found

Are you getting the below error while running Python/Django application on your MacBook Air (with M1 chip)?

OSError: no library called "cairo-2" was found 
no library called "cairo" was found 
no library called "libcairo-2" was found'

I was facing this issue while running the Django web application. Even after installing all the required packages from the requirements.txt file, the problem is not resolved.

Basically, packages like cairo, libcairo and other dependent packages are missing on your MacBook OS.

To solve this issue, you have to install those dependent packages. It’s not so straightforward as there is no package manager in your MacBook to install packages.

After debugging and going through numerous trials, I found the solution. I thought sharing it with you will save you a lot of time.

Follow the steps below.

Step 1: Install Brew Package Manager

MacBook Air (M1 chip) does not come up with the package manager. No worry, you can install it with a single command.

Open your terminal and run the below command.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

You can find more detail about the brew package manager here.

Step 2: Install Packages using Brew Package Manager

Here is the single command to install all the required packages.

brew install cairo pango gdk-pixbuf libxml2 libxslt libffi

After successful installation, run your application. It should be working now! 😀

Additional Step:

Getting an error even after following the above steps?

File "/Users/username/projects/env-cv/lib/python3.9/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library 'pango-1.0': dlopen(pango-1.0, 0x0002): tried: '/usr/local/homebrew/Cellar/cairo/1.14.6_1/lib//pango-1.0' (no such file), '/opt/homebrew/lib/pango-1.0' (no such file), 'pango-1.0' (no such file), '/usr/local/lib/pango-1.0' (no such file), '/usr/lib/pango-1.0' (no such file), '/usr/local/homebrew/Cellar/cairo/1.14.6_1/lib//pango-1.0' (no such file), '/Users/username/projects/cvmaker/pango-1.0' (no such file).  Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0'

Worry not. Run the below command.

brew install pango

Now restart your application.

In the case of the Django application, if you get any error, clean up the complete virtual environment or simply delete and start a new one.

That’s all!

If you still have any issues, share it in the comment section below. I can try my best to help you.

8 Comments

  1. raise OSError(error_message) # pragma: no cover
    OSError: no library called “cairo-2” was found
    no library called “cairo” was found
    no library called “libcairo-2” was found
    cannot load library ‘libcairo.so.2’: dlopen(libcairo.so.2, 0x0002): tried: ‘libcairo.so.2’ (no such file), ‘/System/Volumes/Preboot/Cryptexes/OSlibcairo.so.2’ (no such file), ‘/usr/lib/libcairo.so.2’ (no such file, not in dyld cache), ‘libcairo.so.2’ (no such file), ‘/usr/local/lib/libcairo.so.2’ (no such file), ‘/usr/lib/libcairo.so.2’ (no such file, not in dyld cache). Additionally, ctypes.util.find_library() did not manage to locate a library called ‘libcairo.so.2’
    cannot load library ‘libcairo.2.dylib’: dlopen(libcairo.2.dylib, 0x0002): tried: ‘libcairo.2.dylib’ (no such file), ‘/System/Volumes/Preboot/Cryptexes/OSlibcairo.2.dylib’ (no such file), ‘/usr/lib/libcairo.2.dylib’ (no such file, not in dyld cache), ‘libcairo.2.dylib’ (no such file), ‘/usr/local/lib/libcairo.2.dylib’ (no such file), ‘/usr/lib/libcairo.2.dylib’ (no such file, not in dyld cache). Additionally, ctypes.util.find_library() did not manage to locate a library called ‘libcairo.2.dylib’
    cannot load library ‘libcairo-2.dll’: dlopen(libcairo-2.dll, 0x0002): tried: ‘libcairo-2.dll’ (no such file), ‘/System/Volumes/Preboot/Cryptexes/OSlibcairo-2.dll’ (no such file), ‘/usr/lib/libcairo-2.dll’ (no such file, not in dyld cache), ‘libcairo-2.dll’ (no such file), ‘/usr/local/lib/libcairo-2.dll’ (no such file), ‘/usr/lib/libcairo-2.dll’ (no such file, not in dyld cache). Additionally, ctypes.util.find_library() did not manage to locate a library called ‘libcairo-2.dll’

  2. Hello,

    Thanks for the above, I ran through all of this but still getting an error message of, any ideas on what might be causing this please?

    Traceback (most recent call last):
    File “/Users/lukemoseley/LogicX-Push2-master/app.py”, line 6, in
    import cairocffi as cairo
    File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cairocffi/__init__.py”, line 47, in
    cairo = dlopen(
    ^^^^^^^
    File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cairocffi/__init__.py”, line 44, in dlopen
    raise OSError(error_message) # pragma: no cover
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    OSError: no library called “cairo-2” was found
    no library called “cairo” was found
    no library called “libcairo-2” was found
    cannot load library ‘libcairo.so.2’: dlopen(libcairo.so.2, 0x0002): tried: ‘libcairo.so.2’ (no such file), ‘/System/Volumes/Preboot/Cryptexes/OSlibcairo.so.2’ (no such file), ‘/usr/lib/libcairo.so.2’ (no such file, not in dyld cache), ‘libcairo.so.2’ (no such file), ‘/usr/lib/libcairo.so.2’ (no such file, not in dyld cache). Additionally, ctypes.util.find_library() did not manage to locate a library called ‘libcairo.so.2’
    cannot load library ‘libcairo.2.dylib’: dlopen(libcairo.2.dylib, 0x0002): tried: ‘libcairo.2.dylib’ (no such file), ‘/System/Volumes/Preboot/Cryptexes/OSlibcairo.2.dylib’ (no such file), ‘/usr/lib/libcairo.2.dylib’ (no such file, not in dyld cache), ‘libcairo.2.dylib’ (no such file), ‘/usr/lib/libcairo.2.dylib’ (no such file, not in dyld cache). Additionally, ctypes.util.find_library() did not manage to locate a library called ‘libcairo.2.dylib’
    cannot load library ‘libcairo-2.dll’: dlopen(libcairo-2.dll, 0x0002): tried: ‘libcairo-2.dll’ (no such file), ‘/System/Volumes/Preboot/Cryptexes/OSlibcairo-2.dll’ (no such file), ‘/usr/lib/libcairo-2.dll’ (no such file, not in dyld cache), ‘libcairo-2.dll’ (no such file), ‘/usr/lib/libcairo-2.dll’ (no such file, not in dyld cache). Additionally, ctypes.util.find_library() did not manage to locate a library called ‘libcairo-2.dll’
    lukemoseley@Lukes-Mac-mini LogicX-Push2-master %

Leave a Reply

Your email address will not be published. Required fields are marked *