Kozea / cairocffi

CFFI-based cairo bindings for Python.
https://doc.courtbouillon.org/cairocffi
BSD 3-Clause "New" or "Revised" License
208 stars 54 forks source link

Symbol not found in flat namespace '_ffi_prep_closure' #198

Closed leecbaker closed 3 years ago

leecbaker commented 3 years ago

While installing cairocffi, I'm encountering this runtime linking error. It appears that

Error: While importing 'wsgi', an ImportError was raised:

Traceback (most recent call last):
  File "./project/.venv/lib/python3.9/site-packages/flask/cli.py", line 256, in locate_app
    __import__(module_name)
  File "./project/wsgi.py", line 1, in <module>
    from app import create_app
  File "./project/app/__init__.py", line 33, in <module>
    from app.api import API_BP
  File "./project/app/api/__init__.py", line 27, in <module>
    from .submission_counts import SubmissionCountEndpoint
  File "./project/app/api/submission_counts.py", line 13, in <module>
    from app.submit import (
  File "./project/app/submit.py", line 81, in <module>
    from app.pdf import render_pdf
  File "./project/app/pdf.py", line 7, in <module>
    from flask_weasyprint import HTML
  File "./project/.venv/lib/python3.9/site-packages/flask_weasyprint/__init__.py", line 13, in <module>
    import weasyprint
  File "./project/.venv/lib/python3.9/site-packages/weasyprint/__init__.py", line 469, in <module>
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "./project/.venv/lib/python3.9/site-packages/weasyprint/css/__init__.py", line 27, in <module>
    from . import computed_values, counters, media_queries
  File "./project/.venv/lib/python3.9/site-packages/weasyprint/css/computed_values.py", line 15, in <module>
    from .. import text
  File "./project/.venv/lib/python3.9/site-packages/weasyprint/text.py", line 11, in <module>
    import cairocffi as cairo
  File "./project/.venv/lib/python3.9/site-packages/cairocffi/__init__.py", line 17, in <module>
    from ._generated.ffi import ffi
  File "./project/.venv/lib/python3.9/site-packages/cairocffi/_generated/ffi.py", line 2, in <module>
    import _cffi_backend
ImportError: dlopen(./project/.venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_ffi_prep_closure'

Looking a bit more into which version of libffi is being used:

>otool -L .venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so
.venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so:
    /usr/lib/libffi.dylib (compatibility version 1.0.0, current version 27.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

This was installed by homebrew.

Any idea why this symbol is used but is not in libffi?

liZe commented 3 years ago

Hello!

Any idea why this symbol is used but is not in libffi?

That’s actually a problem with cffi’s wheel. If you’ve updated your system recently, you probably should reinstall cffi. And if it doesn’t work for some reason, pip install cffi --no-binary :all: seems to be the latest solution that will definitely work.

leecbaker commented 3 years ago

@liZe, thanks for your help. Unfortunately, I tried this previously and it didn't help.

If you’ve updated your system recently, you probably should reinstall cffi.

This is a brand new system, less than a week old. Everything has been installed from scratch in the past couple of days.

the latest solution that will definitely work.

Unfortunately, this didn't work:

> pip install cffi --no-binary :all:
Requirement already satisfied: cffi in ./.venv/lib/python3.9/site-packages (1.14.6)
Requirement already satisfied: pycparser in ./.venv/lib/python3.9/site-packages (from cffi) (2.20)
> pip uninstall cffi
Found existing installation: cffi 1.14.6
Uninstalling cffi-1.14.6:
  Would remove:
    ./project/.venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so
    ./project/.venv/lib/python3.9/site-packages/cffi-1.14.6.dist-info/*
    ./project/.venv/lib/python3.9/site-packages/cffi/*
Proceed (Y/n)? y
  Successfully uninstalled cffi-1.14.6
> pip install cffi --no-binary :all:
Collecting cffi
  Using cached cffi-1.15.0.tar.gz (484 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: pycparser in ./.venv/lib/python3.9/site-packages (from cffi) (2.20)
Skipping wheel build for cffi, due to binaries being disabled for it.
Installing collected packages: cffi
    Running setup.py install for cffi ... done
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
weasyprint 52.5 requires cairocffi>=0.9.0, which is not installed.
Successfully installed cffi-1.15.0
(project) ➜  project git:(a-branch) ✗ pip install cairocffi --no-binary :all:
Collecting cairocffi
  Downloading cairocffi-1.3.0.tar.gz (88 kB)
     |████████████████████████████████| 88 kB 6.7 MB/s
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: ./project/.venv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/34/ff08ny7j04g540qfn_rhnnp80000gn/T/pip-install-ku135qxk/cairocffi_9590ab2329c74a679626677ffb4c7d9a/setup.py'"'"'; __file__='"'"'/private/var/folders/34/ff08ny7j04g540qfn_rhnnp80000gn/T/pip-install-ku135qxk/cairocffi_9590ab2329c74a679626677ffb4c7d9a/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/34/ff08ny7j04g540qfn_rhnnp80000gn/T/pip-pip-egg-info-n9nk2_dl
       cwd: /private/var/folders/34/ff08ny7j04g540qfn_rhnnp80000gn/T/pip-install-ku135qxk/cairocffi_9590ab2329c74a679626677ffb4c7d9a/
  Complete output (29 lines):
  ./project/.venv/lib/python3.9/site-packages/setuptools/__init__.py:148: SetuptoolsDeprecationWarning: setup_requires is deprecated. Supply build dependencies using PEP 517 pyproject.toml build-requires.
    warnings.warn(
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/private/var/folders/34/ff08ny7j04g540qfn_rhnnp80000gn/T/pip-install-ku135qxk/cairocffi_9590ab2329c74a679626677ffb4c7d9a/setup.py", line 10, in <module>
      setup(
    File "./project/.venv/lib/python3.9/site-packages/setuptools/__init__.py", line 159, in setup
      return distutils.core.setup(**attrs)
    File "/Users/lee/.pyenv/versions/3.9.7/lib/python3.9/distutils/core.py", line 108, in setup
      _setup_distribution = dist = klass(attrs)
    File "./project/.venv/lib/python3.9/site-packages/setuptools/dist.py", line 453, in __init__
      _Distribution.__init__(
    File "/Users/lee/.pyenv/versions/3.9.7/lib/python3.9/distutils/dist.py", line 292, in __init__
      self.finalize_options()
    File "./project/.venv/lib/python3.9/site-packages/setuptools/dist.py", line 831, in finalize_options
      ep(self)
    File "./project/.venv/lib/python3.9/site-packages/setuptools/dist.py", line 852, in _finalize_setup_keywords
      ep.load()(self, ep.name, value)
    File "./project/.venv/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 219, in cffi_modules
      add_cffi_module(dist, cffi_module)
    File "./project/.venv/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
      execfile(build_file_name, mod_vars)
    File "./project/.venv/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 25, in execfile
      exec(code, glob, glob)
    File "cairocffi/ffi_build.py", line 28, in <module>
      ffi = FFI()
    File "./project/.venv/lib/python3.9/site-packages/cffi/api.py", line 48, in __init__
      import _cffi_backend as backend
  ImportError: dlopen(./project/.venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_ffi_prep_closure'
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/8b/d2/137b346d64f0d6428a90f60b51a06706592a86b74fd21ff66c853537cb9b/cairocffi-1.3.0.tar.gz#sha256=108a3a7cb09e203bdd8501d9baad91d786d204561bd71e9364e8b34897c47b91 (from https://pypi.org/simple/cairocffi/) (requires-python:>=3.7). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading cairocffi-1.2.0.tar.gz (70 kB)
     |████████████████████████████████| 70 kB 21.4 MB/s
  Preparing metadata (setup.py) ... error
liZe commented 3 years ago

Unfortunately, this didn't work:

Hmmmm, sorry to hear that. Then you’ll probably have to ping the CFFI maintainers, because the problem is not in CairoCFFI and I’ll be totally incompetent to help you about this kind of problems 😉. That’s exactly the same problem as the one linked above, I suppose that they’ll give you a solution that really works for you 🤞.