025-01-12T21:00:55.317026782Z Traceback (most recent call last): 2025-01-12T21:00:55.317060583Z File "/opt/python/3.12.2/lib/python3.12/site-packages/gunicorn/util.py", line 26, in <module> 2025-01-12T21:00:55.317333892Z import importlib.metadata as

Joshi, Shubham 0 Reputation points
2025-01-12T21:11:56.92+00:00

I am facing issue while running my server same code with same requirements.txt file I am able to run in local but at Azure I am facing issue:

025-01-12T21:00:55.317026782Z Traceback (most recent call last):

2025-01-12T21:00:55.317060583Z File "/opt/python/3.12.2/lib/python3.12/site-packages/gunicorn/util.py", line 26, in <module>

2025-01-12T21:00:55.317333892Z import importlib.metadata as importlib_metadata

2025-01-12T21:00:55.317350992Z File "/opt/python/3.12.2/lib/python3.12/importlib/metadata/init.py", line 7, in <module>

2025-01-12T21:00:55.318029713Z import pathlib

2025-01-12T21:00:55.318048014Z File "/tmp/8dd3348ff8bf63d/antenv/lib/python3.12/site-packages/pathlib.py", line 10, in <module>

2025-01-12T21:00:55.318751435Z from collections import Sequence

2025-01-12T21:00:55.318803837Z ImportError: cannot import name 'Sequence' from 'collections' (/opt/python/3.12.2/lib/python3.12/collections/init.py)

2025-01-12T21:00:55.318896740Z

2025-01-12T21:00:55.318935841Z During handling of the above exception, another exception occurred:

2025-01-12T21:00:55.318948541Z

2025-01-12T21:00:55.318954641Z Traceback (most recent call last):

2025-01-12T21:00:55.318960142Z File "/opt/python/3/bin/gunicorn", line 5, in <module>

2025-01-12T21:00:55.318976442Z from gunicorn.app.wsgiapp import run

2025-01-12T21:00:55.318982642Z File "/opt/python/3.12.2/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 9, in <module>

2025-01-12T21:00:55.319903071Z from gunicorn.app.base import Application

2025-01-12T21:00:55.319922971Z File "/opt/python/3.12.2/lib/python3.12/site-packages/gunicorn/app/base.py", line 11, in <module>

2025-01-12T21:00:55.320287482Z from gunicorn import util

2025-01-12T21:00:55.320305383Z File "/opt/python/3.12.2/lib/python3.12/site-packages/gunicorn/util.py", line 28, in <module>

2025-01-12T21:00:55.320314983Z import importlib_metadata

2025-01-12T21:00:55.320322883Z ModuleNotFoundError: No module named 'importlib_metadata'

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,213 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 18,811 Reputation points
    2025-01-14T05:42:21.17+00:00

    Hi @Joshi, Shubham the error message you're facing indicates an issue with the importlib_metadata module in your Python environment on Azure. That module is used for package metadata inspection in Python versions 3.8 and above. The

    **ImportError: cannot import name 'Sequence' from 'collections'**error suggests a potential incompatibility between the pathlib and collections modules in your environment.

    The importlib_metadata module might not be installed in your Azure Python environment, even though it's present locally. It seems like there might be subtle differences between your local Python environment and the one on Azure, leading to compatibility issues.

    Follow these steps to try resolving the issue:

    1. Install importlib_metadata: There's a high chance the module is simply missing. You can install it using pip:
    
    pip install importlib_metadata
    
    

    Run this command on your Azure app service or virtual machine where your code is deployed.

    1. Check requirements.txt: Ensure your requirements.txt file explicitly lists importlib_metadata as a dependency. If it's not present, add it and redeploy your application.
    2. Review Environment Compatibility: If installing the module doesn't resolve the issue, consider these:
    • Double-check that the Python version on Azure matches your local environment. You can verify this using python --version on both machines.
    • In rare cases, conflicting packages might cause issues. Try creating a clean virtual environment on Azure and installing only the required packages from your requirements.txt.

    Hope that helps.

    -Grace

    0 comments No comments

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.