[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.
Comments
Pranay
Thanks a lot this was helpful!
Aniruddha Chaudhari
I’m glad this helped you to solve your problem.