zappa / Zappa

Serverless Python
https://zappa.ws/zappa
MIT License
3.33k stars 363 forks source link

[Migrated] ModuleNotFoundError: No module named 'pyinstrument_cext' when deploying with Python 3.8 #841

Closed jneves closed 7 months ago

jneves commented 3 years ago

Originally from: https://github.com/Miserlou/Zappa/issues/2083 by dphang

Context

I am using pyinstrument which is using pyinstrument_cext. It seems like it isn't compatible with Python 3.8. Getting this error when updating the deployment:

Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.

Upon looking at logs, it is due to module pyinstrument_cext not found. See below for full logs.

Expected Behavior

It should deploy successfully with pyinstrument and pyinstrument_cext on Python 3.8

Actual Behavior

It gives this error in the logs when deploying pyinstrument on Python 3.8:

[ERROR] ModuleNotFoundError: No module named 'pyinstrument_cext'
Traceback (most recent call last):
  File "/var/task/handler.py", line 609, in lambda_handler
    return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 240, in lambda_handler
    handler = cls()
  File "/var/task/handler.py", line 146, in __init__
    wsgi_app_function = get_django_wsgi(self.settings.DJANGO_SETTINGS)
  File "/var/task/zappa/ext/django_zappa.py", line 20, in get_django_wsgi
    return get_wsgi_application()
  File "/tmp/sample-backend/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/tmp/sample-backend/django/core/handlers/wsgi.py", line 127, in __init__
    self.load_middleware()
  File "/tmp/sample-backend/django/core/handlers/base.py", line 35, in load_middleware
    middleware = import_string(middleware_path)
  File "/tmp/sample-backend/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/var/lang/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/sample-backend/pyinstrument/__init__.py", line 1, in <module>
    from pyinstrument.profiler import Profiler
  File "/tmp/sample-backend/pyinstrument/profiler.py", line 6, in <module>
    from pyinstrument_cext import setstatprofile

Possible Fix

  1. Using Python 3.7 worked for now.
  2. Unfortunately, I am not an expert in the c extensions. Maybe related to Python 3.8 running on Amazon Linux 2 vs. Amazon Linux for older Python versions?

Steps to Reproduce

  1. Configure Zappa json with python3.8
  2. Install pyinstrument which installs pyinstrument-cext
  3. Deploy zappa

Your Environment

{
  "dev": {
    "aws_region": "us-west-1",
    "django_settings": "sample.devo_settings",
    "profile_name": "default",
    "project_name": "sample-backend",
    "runtime": "python3.8",
    "s3_bucket": "<blah>",
    "slim_handler": true,
    "keep_warm_expression": "rate(4 minutes)",
    "certificate_arn": "<blah>",
    "memory_size": 1024
  }
}

(note I do exclude a lot of requirements above in the config file, some are needed as the project is deployed in a server environments too)

selected-pixel-jameson commented 1 year ago

I'm experiencing a very similar situation with elasticsearch.

github-actions[bot] commented 7 months ago

Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.

github-actions[bot] commented 7 months ago

Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.