djangolambdazappapython-zappa

Zappa: No module named '_cffi_backend'


I recently uploaded an Django application with the use off Zappa, which was running perfectly fine.

Now, I wanted to update this application, and It suddenly gives me this error: (The changes I made wasn't really that much, removed a blank=True in my models.py)

ModuleNotFoundError: No module named '_cffi_backend'
Traceback (most recent call last):
  File "/var/task/handler.py", line 657, in lambda_handler
    return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 251, in lambda_handler
    handler = cls()
  File "/var/task/handler.py", line 160, in __init__
    wsgi_app_function = get_django_wsgi(self.settings.DJANGO_SETTINGS)
  File "/var/task/zappa/ext/django_zappa.py", line 21, in get_django_wsgi
    return get_wsgi_application()
  File "/tmp/mysite/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/tmp/mysite/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/tmp/mysite/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/tmp/mysite/core/apps.py", line 8, in ready
    from core import signals
  File "/tmp/mysite/core/signals.py", line 1, in <module>
    import cairosvg
  File "/tmp/mysite/cairosvg/__init__.py", line 26, in <module>
    from . import surface  # noqa isort:skip
  File "/tmp/mysite/cairosvg/surface.py", line 9, in <module>
    import cairocffi as cairo
  File "/tmp/mysite/cairocffi/__init__.py", line 17, in <module>
    from ._generated.ffi import ffi
  File "/tmp/mysite/cairocffi/_generated/ffi.py", line 2, in <module>
    import _cffi_backend

I use a package CairoSVG and when disabling this, my application works again. The weird thing is that I was using this package in previous version aswell without any problems.

when updating with zappa update dev it shows me this:

Calling update for stage dev..
Downloading and installing dependencies..
 - reportlab==3.6.6: Using locally cached manylinux wheel
 - pyproj==3.3.0: Using locally cached manylinux wheel
 - psycopg2-binary==2.9.3: Using locally cached manylinux wheel
'releases'
Packaging project as gzipped tarball.

I've noticed that on previous updates, there was a 4th dependency called "cffi" but is gone now.

I have no idea how it's gone and from where those dependenties come from because I have much more in my requirements.txt


Solution

  • Don't exactly know what went wrong but I got it fixed by:

    1. completly removing my virtual environment
    2. creating a new one.
    3. installing packages with pip install -r requirements.txt --no-cache-dir

    the --no-cache-dir was really important adding.