Gunicorn not compatible with Python > 3.10

Jason Wong 5 Reputation points
2023-01-19T00:12:11.5233333+00:00

Whenever I deploy on WebApp, I get this trace.

2023-01-18T23:47:37.542017057Z Traceback (most recent call last):
2023-01-18T23:47:37.542841660Z File "/tmp/8daf9ad5ac482f6/antenv/bin/gunicorn", line 5, in
2023-01-18T23:47:37.543544762Z from gunicorn.app.wsgiapp import run
2023-01-18T23:47:37.543562662Z File "/tmp/8daf9ad5ac482f6/antenv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 9, in
2023-01-18T23:47:37.543843363Z from gunicorn.app.base import Application
2023-01-18T23:47:37.544277564Z File "/tmp/8daf9ad5ac482f6/antenv/lib/python3.10/site-packages/gunicorn/app/base.py", line 11, in
2023-01-18T23:47:37.544686265Z from gunicorn import util
2023-01-18T23:47:37.544729466Z File "/tmp/8daf9ad5ac482f6/antenv/lib/python3.10/site-packages/gunicorn/util.py", line 25, in
2023-01-18T23:47:37.552215989Z import pkg_resources
2023-01-18T23:47:37.552802890Z File "/tmp/8daf9ad5ac482f6/antenv/lib/python3.10/site-packages/pkg_resources/init.py", line 23, in
2023-01-18T23:47:37.553468492Z import zipfile
2023-01-18T23:47:37.553485692Z File "/opt/python/3.10.4/lib/python3.10/zipfile.py", line 19, in
2023-01-18T23:47:37.563566023Z import pathlib
2023-01-18T23:47:37.563587723Z File "/tmp/8daf9ad5ac482f6/antenv/lib/python3.10/site-packages/pathlib.py", line 10, in
2023-01-18T23:47:37.563593823Z from collections import Sequence
2023-01-18T23:47:37.563597723Z ImportError: cannot import name 'Sequence' from 'collections' (/opt/python/3.10.4/lib/python3.10/collections/init.py)

Seems like Python 3.10 is not compatible?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,937 questions
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Roderick Bant 2,056 Reputation points
    2023-01-19T11:36:10.7766667+00:00

    Hi, thank you for your question at Q&A. I understand that you want to run an Azure WebApp with Python 3.10 and are having issues importing gunicorn.

    On the PyPi page for gunicorn the Python versions listed for the current 20.1.0 version of gunicorn are 3.5, 3.6, 3.7, 3.8 and 3.9. So Python 3.10 is currently not listed as a compatible version.

    0 comments No comments

  2. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2023-02-02T17:58:33.0033333+00:00

    @Jason Wong it's compatible. I was successfully able to run a Python 3.10.0 app on Azure using gunicorn. I did have the same issue you had but was able to resolve it by using collection.abc instead of collection.

    from collections.abc import Sequence
    from flask import Flask
    
    def is_it_a_sequence(obj):
        return isinstance(obj, Sequence)
    
    print(is_it_a_sequence([1, 2, 3])) # True
    print(is_it_a_sequence('abc')) # True
    
    

    Since my Python project is a Visual Studio Python template project, my startup command for my app service is gunicorn --bind=0.0.0.0 --timeout 600 runserver:app with runtime configured as 3.10.

    User's image

    0 comments No comments

  3. Kyle 0 Reputation points
    2023-11-11T20:48:53.9533333+00:00

    Hi I am having this issue when deploying a flask app to an App Service - the github actions build is fine and it deploys, but I see the same error logs in azure console.

    Ryan I feel like your solution is only if I am importing Sequences in my own code, which i'm not. Is there a solution for this?

    Thanks

      Warning
    2023-11-11T20:33:35.8867203
    During handling of the above exception, another exception occurred:
      Ok
    2023-11-11T20:33:35.8867241
      Ok
    2023-11-11T20:33:35.8867276
    Traceback (most recent call last):
      Ok
    2023-11-11T20:33:35.8867313
      File "/tmp/8dbe2f1b508822a/antenv/bin/gunicorn", line 5, in <module>
      Ok
    2023-11-11T20:33:35.8949483
        from gunicorn.app.wsgiapp import run
      Ok
    2023-11-11T20:33:35.8949715
      File "/tmp/8dbe2f1b508822a/antenv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 9, in <module>
      Ok
    2023-11-11T20:33:35.8949773
        from gunicorn.app.base import Application
      Ok
    2023-11-11T20:33:35.894981
      File "/tmp/8dbe2f1b508822a/antenv/lib/python3.11/site-packages/gunicorn/app/base.py", line 11, in <module>
      Ok
    2023-11-11T20:33:35.8949848
        from gunicorn import util
      Ok
    2023-11-11T20:33:35.8949882
      File "/tmp/8dbe2f1b508822a/antenv/lib/python3.11/site-packages/gunicorn/util.py", line 28, in <module>
      Ok
    2023-11-11T20:33:35.8964016
        import importlib_metadata
      Ok
    2023-11-11T20:33:35.8964201
      File "/tmp/8dbe2f1b508822a/antenv/lib/python3.11/site-packages/importlib_metadata/__init__.py", line 6, in <module>
      Ok
    2023-11-11T20:33:35.8964258
        import zipp
      Ok
    2023-11-11T20:33:35.8964296
      File "/tmp/8dbe2f1b508822a/antenv/lib/python3.11/site-packages/zipp/__init__.py", line 3, in <module>
      Ok
    2023-11-11T20:33:35.8964336
        import zipfile
      Ok
    2023-11-11T20:33:35.8964377
      File "/opt/python/3.11.4/lib/python3.11/zipfile.py", line 19, in <module>
      Ok
    2023-11-11T20:33:35.8978545
        import pathlib
      Ok
    2023-11-11T20:33:35.8978744
      File "/tmp/8dbe2f1b508822a/antenv/lib/python3.11/site-packages/pathlib.py", line 10, in <module>
      Ok
    2023-11-11T20:33:35.8978807
        from collections import Sequence
      Ok
    2023-11-11T20:33:35.8978848
    ImportError: cannot import name 'Sequence' from 'collections' (/opt/python/3.11.4/lib/python3.11/collections/__init__.py)
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.