0

The issue is quite simple. I've installed Python and Cairo with Homebrew since I use a M1 MacBook. When trying to import the package, I get this error:

>>> import cairo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cairo/__init__.py", line 1, in <module>
    from ._cairo import *  # noqa: F401,F403
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cairo/_cairo.cpython-39-darwin.so, 2): Symbol not found: _cairo_append_path
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cairo/_cairo.cpython-39-darwin.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cairo/_cairo.cpython-39-darwin.so

Thank you in advance.

1 Answers1

1

Looking at this issue over on their GitHub, and in particular this comment, you could try a couple things:

  • Use Python 3.9 if you're not already (and use python3 in the terminal)
  • Uninstall pycairo as you have it now and install py3cairo with homebrew
  • Create a new venv with python3 and the --system-site-package option i.e. python3 -m venv --system-site-package path/to/env

Check out the comment itself, and let me know if any of this works. There didn't seem to be one clear solution for the issue.

Rolv Apneseth
  • 2,078
  • 2
  • 7
  • 19
  • Hi, thank you very much for the answer. I try the three methods (well, I was already using python3) but nothing work, I keep getting the exact same error. – Mario Vago Marzal Jun 26 '21 at 11:20
  • Anything else on that issue help out? Such as the steps he took with homebrew – Rolv Apneseth Jun 26 '21 at 12:33
  • Otherwise I suggest commenting on that issue again that the fixes did not resolve your issue and hopefully one of the maintainers can help you out – Rolv Apneseth Jun 26 '21 at 12:34
  • I read the issue and what I've noticed is that I'm not sure if when running python3 with the terminal it is running the version I have installed with Homebrew. How do I ensure this? – Mario Vago Marzal Jun 27 '21 at 10:52
  • Either check the version to make sure it's the right one with `python3 --version` or check if the executable is the one you want to use ([use this](https://stackoverflow.com/a/2589722/14316282) to find the executable it's running). – Rolv Apneseth Jun 27 '21 at 13:23