-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"OSError: no library called "cairo-2" was found" after install #354
Comments
Hello! If you want to use CairoSVG with Homebrew (and that’s a good idea), you have to use Homebrew’s Python. The If |
So I'm using my virtual environment, the one you mentioned. The command for finding homebrew's Python didn't work, but I did
Doing I don't necessarily want to use CairoSVG with Homebrew. Let me explain my goal: I want to use a Python package called drawSvg, which uses CairoSVG to convert from SVG to PNG. I have my virtual environment. So that's my goal. I have done |
Did you use Homebrew’s Python to create the virtual environment? It’s mandatory if you want to use Homebrew’s packages in your venv. |
How do I check that? I'm happy to create a new virtualenv for testing this. Outside of my environment, if I call If I call
It's possible I might have setup virtualenv using conda, because this didn't work via brew for M1 Macs. cairo 1.16.0 is installed within conda, however. |
That’s hard to know. Creating a new one is probably the best way to be sure.
You have to use |
I'm just trying to find out... how do I install CairoSVG? |
It means that you have another custom version of Python installed, that’s why it doesn’t work.
What you have to do is:
|
I did everything, it still does not work. Even if it did, this whole way of this to work is entirely broken... I'm just gonna use another library to convert one svg to a png instead of bringing god knows how many system level deps and hacky-wacky config into our project. |
I hope that you’ll find the library that suits your need. |
@liZe that person isn't me, just someone I guess with the same issue. Your steps worked for me, thank you. I would agree that it's an issue that for me to use a library such as drawSvg, I have to setup my entire environment in a specific way to accommodate Cairo. Perhaps this is just a M1 issue, but I'd be worried, if I wanted to run this on a server or host it on GitHub, others would need to do the same complicated process to get it to run? |
Oh, OK.
😃
On Linux, it’s pretty easy to setup. As there’s a package manager in all the major distributions of Linux, installing Cairo is really easy and there’s no problem with multiple versions of Python installed on the same system (ie. there’s no need to configure Homebrew). CairoSVG is actually already packaged for many distributions, so you can install it and all its dependencies with just one command. If you want to use CairoSVG on a server, it will be much easier on Linux. On macOS and Windows, it’s more complicated, that’s true. Many macOS and Windows users are used to graphical installers, and installing CairoSVG is really different. Even for developers, it’s often more complicated than many libraries to install. But to be fully honest, we don’t think that it’s that complicated on a fresh macOS installation. You can install it with:
If these steps don’t work, it means that other install software is interfering with CairoSVG: you may have installed other versions of Python, or Cairo, or… It’s really hard to manage these cases, as there are as many cases as there are users. For example, you had Python 3 installed in And that’s even more complicated on Windows… We spent countless days (weeks? months?) to make our libraries easier to install. We actually re-wrote our SVG engine (and our HTML/CSS engine) for WeasyPrint, to avoid depending on Cairo and avoid countless issues. It worked quite well, but… CairoSVG deeply relies on Cairo, and we can’t do this for this project. We don’t even have a Mac or a Windows computer. And, more important, we don’t have enough time. |
If you end up looking at this issue and get stuck, checkout this SO suggestion to use inkscape. This worked for me on my M1 Mac. """Walk the input folder for each SVG create a PNG in the output folder
"""
from pathlib import Path, PurePath
import subprocess
svg_files = list(Path("input").glob("**/*.svg"))
for svg in svg_files:
new_png = svg
np_list = str(new_png).split("/")
np_list[0] = "output"
new_png = PurePath("/".join(np_list))
new_png = new_png.with_suffix(".png")
print(f"{svg} {new_png}")
# check if the png folder hierarchy exists or create it
if not Path(new_png.parent).exists():
Path(new_png.parent).mkdir(parents=True)
subprocess.Popen(['inkscape',"-p", f"{str(svg)}", "-o", f"{str(new_png)}", "--export-dpi=1200"]) |
For those looking for a better workaround, do this before you from ctypes.macholib import dyld
dyld.DEFAULT_LIBRARY_FALLBACK.append("/opt/homebrew/lib") macOS doesn't allow to override any of the standard DYLD environment variables, so this is the least intrusive way of adding |
Or just create your virtual environment using Homebrew’s Python, as explained above… |
@liZe that advice doesn't work when you run multiple projects using different python versions managed by pyenv. |
Doesn’t Homebrew’s pyenv handle this for you? |
M1 Macos 12.2.1 after running
|
Then you’ll have to ask the Hombrew devs how you can use pyenv with Homebrew’s libraries. |
Homebrew installs to `/opt/homebrew/lib` on M1 Macs, instead of `/usr/local/lib` on Intel Macs. Without disabling SIP (to set DYLD_FALLBACK_LIBRARY_PATH in env) or manually changing the `DEFAULT_LIBRARY_FALLBACK` before loading any third-party libraries (as proposed here: Kozea/CairoSVG#354 (comment)), libraries installed with homebrew can not be loaded.
If nothing helped you, try this workaround.
This is a way to create symbolic links locally. |
Same problem. Running normal installation of python (3.11.0) and pip (22.3.1). |
I'm also running into this issue -- the tip from @sinwoobang solved it for me after other recommendations failed. It seems plausible this is a Homebrew issue and not a CairoSVG issue so I understand why this issue is closed but it'd be great if this error was documented somewhere and a consistent workaround provided. I imagine many users with Apple silicon are running into this error. |
We don’t own a Apple computer, so we can’t test anything. If anyone is interested in providing a reliable workaround (and answering the people that will get the bug, even with the workaround), your help is welcome! |
The tip from @sinwoobang solved it for me too after I tried all the other suggestions on this page, which did not work. Thanks @sinwoobang!! |
I was facing similar issue in Mac M2, and resolved by installing the cairo using
Note: Make sure to run your application from terminal enabled with |
I've been trying to install cairosvg, but run into errors. For example, I've tried installing via:
pip3 install cairosvg
pip install cairosvg
brew install cairo
But then just running
cairosvg
in Terminal, I get this error:It's similar if I run
import cairosvg
in Python:If I run
brew list
,cairo
is listed. If I runpip list
, the same thing:I'm running macOS 12.0.1, on an M1 Mac (which I think may be a hint towards the problem).
The text was updated successfully, but these errors were encountered: