Skip to content
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

[Apple Silicon] ImportError : Symbol not found: _cairo_append_path #226

Closed
Franciscortega opened this issue Feb 21, 2021 · 24 comments
Closed

Comments

@Franciscortega
Copy link

Franciscortega commented Feb 21, 2021

Hi everyone !

I just migrated to a new M1 MBP and I'm setting up a Django project. I managed to set up all dependencies, but when starting the server I got stopped by an import error :

Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/cairo/__init__.py", line 1, in <module>
    from ._cairo import *  # noqa: F401,F403
ImportError: dlopen(/Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/cairo/_cairo.cpython-37m-darwin.so, 2): Symbol not found: _cairo_append_path
  Referenced from: /Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/cairo/_cairo.cpython-37m-darwin.so
  Expected in: flat namespace
 in /Users/someuser/src/virtualenvs/p37env/lib/python3.7/site-packages/cairo/_cairo.cpython-37m-darwin.so

Anyone have faced the same issue and managed to solve it ?

Some infos :

  • python 3.7.9 on an venv created directly with python3.7 -m venv (had the same issue with 3.8 though)
  • Tried both Terminal and Terminal using Rosetta
  • I have a very basic understanding of how all this works deep inside, just trying my best to fight all the issues brought by new ARM architecture :)

Thanks !

@naveen521kk
Copy link
Contributor

Try reinstalling

python -m pip install pycairo --force

@Franciscortega
Copy link
Author

@naveen521kk pycairo-1.20.0 was reinstalled successfully, but it didn't solve the issue

@naveen521kk
Copy link
Contributor

How did you install Cairo?

@Franciscortega
Copy link
Author

Franciscortega commented Feb 22, 2021

I used homebrew. I tried both install via arm native brew version (brew install cairo under native terminal) and x86 (arch -x86_64 /usr/local/homebrew/bin/brew install cairo under Rosetta emulated Terminal). I've also tried several uninstalls and re-installs but only via homebrew.

@naveen521kk
Copy link
Contributor

does installing pycairo using homebrew works? https://formulae.brew.sh/formula/py3cairo#default

@Franciscortega
Copy link
Author

I didn't know if I should keep the pip installation or not when installing pycairo via homebrew (that's were my understanding of underneath logic begins) so I tried both :

  • If installation done with brew install py3cairo and pip package uninstalled : ModuleNotFoundError: No module named 'cairo'
  • If both are present, still got the same error as before

Am I missing something with the configuration of my python environment when installing pycairo with homebrew only ?

@naveen521kk
Copy link
Contributor

Not a mac user here. But it is worth reading https://docs.brew.sh/Homebrew-and-Python.

@Franciscortega
Copy link
Author

Ok I finally solved the problem, but I did a lot of things so I couldn't tell what was the exact problem solver. Here are some details for posterity :

  • My python installations and brew management was a mess so I started by uninstalling brew from rosetta terminal and "ARM" terminal, and then re-install it only under Rosetta Terminal ;
  • I switched to Python 3.9 (and made sure the python3 under terminal was correctly linked to the version installed with homebrew)
  • I installed py3cairo with hombrew as suggested by @naveen521kk
  • I created a new venv with python3 + the --system-site-package option so that the environment could inherit from the global packages installed by Homebrew, and therefore get pycairo from brew installation (python3 -m venv --system-site-package path/to/env)

The combination of all these steps solved all my issues, including this Symbol not found: _cairo_append_path error. Thanks @naveen521kk for your help !

@iamgigahex
Copy link

iamgigahex commented Feb 23, 2021

Hi @naveen521kk tired @Franciscortega solution but somehow still showing the same error.

@naveen521kk
Copy link
Contributor

Even with the brew package of pycairo?

@iamgigahex
Copy link

Yeah, followed by the link that you shared on the previous comments. Only difference is trying it with python 3.7

@naveen521kk
Copy link
Contributor

Well if you are using the one from brew, I think you should use Python 3.9. Only then it will work.

@iamgigahex
Copy link

It worked with 3.9, Thank you @naveen521kk

@kushaalrao
Copy link

I tried this out, but after I do all of those steps I am getting the error module Cairo not found. When I call brew install py3cairo however, it says it's already installed. Any idea how to fix this?

@Timothysit
Copy link

I tried the above methods in a conda environment (using python 3.9, doing brew install py3cairo) but that didn't help. Using conda install works: conda install -c conda-forge pygobject

@mvargasevans
Copy link

@Timothysit
This works.

@EdwardWooCN
Copy link

I tried the above methods in a conda environment (using python 3.9, doing brew install py3cairo) but that didn't help. Using conda install works: conda install -c conda-forge pygobject

This works, and no need to follow setups of @Franciscortega if you have followed https://docs.manim.community/en/stable/installation.html.

@nugen0x
Copy link

nugen0x commented Mar 11, 2022

Is the cairo mentioned above language for StarkNet or something else?

@naveen521kk
Copy link
Contributor

It's something else https://cairographics.org

@tyteen4a03
Copy link

Hi, I'm running into this issue and for operational reasons cannot upgrade to 3.9. Are there any workarounds for this?

@jjin-ut
Copy link

jjin-ut commented Nov 29, 2022

I had been having this issue. I was using anaconda virtual env on M1, tried everything but didn't fix it. @Franciscortega 's comment on --system-site-package made me think maybe I should try using python venv. Create a virtual env using python -m venv ./venv fixed the problem. I tried both python 10 and 11, and both worked.

@ebrire
Copy link

ebrire commented May 11, 2023

I did have this issue on a MacBook Pro with an M2 chip (I was trying to install Manim to create animations). I fixed it by blowing away my whole Python ecosystem on my laptop and reinstalling from scratch. I received the machine with a mix of Python 3.9, 3.10 and 3.11 installed plus PyCharm with virtual environments. I uninstalled everything (including pip3) and used BREW to install Python 3.11 from scratch. Then all libraries were installed as ARM64. As the last step, I installed PyCharm, I blew away the venvs and set up the interpreter 3.11 and inherit the global libraries. I believe the same would work if I only chose Python 3.9, it's more about avoiding a big mishmash of software versions and CPU architectures on the same computer.

@lextoumbourou
Copy link

lextoumbourou commented Aug 5, 2023

Not sure why this issue is closed? It would be great to see pycairo working via pip in Apple Silicon.

Here's the steps to reproduce the error:

(using a python3.9 version downloaded from Python)

> python3.9 -m venv .env
> source .env/bin/activate
> pip install pycairo
> python -m cairo
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/Users/lex/.env/lib/python3.9/site-packages/cairo/__init__.py", line 1, in <module>
    from ._cairo import *  # noqa: F401,F403
ImportError: dlopen(/Users/lex/.env/lib/python3.9/site-packages/cairo/_cairo.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_cairo_tee_surface_add'

Edit: okay, works using python3.10. Just simply replace python3.9 with python3.10 in my example and it imports okay.

@nathancarter
Copy link

Anyone arriving here because you searched up an error that Manim gave you, see the solution here:
https://docs.manim.community/en/latest/faq/installation.html#i-am-using-anaconda-and-get-an-importerror-mentioning-that-some-symbol-is-not-found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests