Azure App Service - FastAPI Deployment Fails Due to Missing Modules Despite Successful GitHub Actions Installation

Harshit Gupta 60 Reputation points
2025-03-25T19:55:31.4066667+00:00

I have deployed a FastAPI service on Azure App Service using GitHub Actions for continuous deployment. The deployment completes successfully, and all dependencies (including uvicorn and other required modules) are installed during the GitHub Actions workflow. However, when the application starts on Azure App Service, it fails with an error stating that the uvicorn module is not found.

Despite verifying that the necessary packages are installed in GitHub Actions, the production logs on Azure App Service consistently show "Module Not Found" errors for dependencies that were successfully installed.

Troubleshooting Steps Taken:

  1. Confirmed that requirements.txt contains all necessary dependencies.
  2. Verified that GitHub Actions successfully installs all dependencies.
  3. Checked Azure App Service log stream, which still reports missing modules.
  4. Tried redeploying, but the issue persists.

Environment Details:

  • App Service Plan: (Provide your plan details, e.g., B1, S1)
  • Python Version: (Specify the Python version in use)
  • Deployment Method: GitHub Actions
  • Startup Command: uvicorn app.main:app --host 0.0.0.0 --port 8000 (if different, specify your command)

Expected Behavior: The FastAPI app should start successfully after deployment without missing module errors.

Observed Behavior:

  • The deployment succeeds in GitHub Actions.
  • The app fails to start on Azure App Service due to missing module errors (ModuleNotFoundError: No module named 'uvicorn').
  • Other installed dependencies are also not recognized in the production logs.

Request for Support: Could you assist in identifying why the installed dependencies are not recognized by Azure App Service and suggest a resolution to ensure the application starts correctly?I have deployed a FastAPI service on Azure App Service using GitHub Actions for continuous deployment. The deployment completes successfully, and all dependencies (including uvicorn and other required modules) are installed during the GitHub Actions workflow. However, when the application starts on Azure App Service, it fails with an error stating that the uvicorn module is not found.

Despite verifying that the necessary packages are installed in GitHub Actions, the production logs on Azure App Service consistently show "Module Not Found" errors for dependencies that were successfully installed.

Troubleshooting Steps Taken:

  1. Confirmed that requirements.txt contains all necessary dependencies.
  2. Verified that GitHub Actions successfully installs all dependencies.
  3. Checked Azure App Service log stream, which still reports missing modules.
  4. Tried redeploying, but the issue persists.

Environment Details:

  • App Service Plan: (Provide your plan details, e.g., B1, S1)
  • Python Version: (Specify the Python version in use)
  • Deployment Method: GitHub Actions
  • Startup Command: uvicorn app.main:app --host 0.0.0.0 --port 8000 (if different, specify your command)

Expected Behavior:
The FastAPI app should start successfully after deployment without missing module errors.

Observed Behavior:

  • The deployment succeeds in GitHub Actions.
  • The app fails to start on Azure App Service due to missing module errors (ModuleNotFoundError: No module named 'uvicorn').
  • Other installed dependencies are also not recognized in the production logs.

Request for Support:
Could you assist in identifying why the installed dependencies are not recognized by Azure App Service and suggest a resolution to ensure the application starts correctly?

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

1 answer

Sort by: Most helpful
  1. Siva Nair 1,400 Reputation points Microsoft External Staff
    2025-03-26T04:37:37.1866667+00:00

    Hi Harshit Gupta,

    Lets follow few troubleshooting steps to get more clarity about the issue,

    1. Ensure that the Python version specified in your Azure App Service matches the version used in your GitHub Actions workflow. You can specify the Python version in the runtime.txt file in your repository. python-3.9.7
    2. Ensure that the requirements.txt file is in the root directory of your repository or specify the correct path in your GitHub Actions workflow.
    3. Ensure that your GitHub Actions workflow installs the dependencies correctly and uses the same Python version as your Azure App Service.
    4. Ensure that the Azure App Service is configured to use the correct Python version. You can set this in the Azure Portal under the "Configuration" section.
    5. Verify that the startup command is correctly set in the Azure App Service. You can set this in the Azure Portal under the "Configuration" section, in the "General settings" tab.
      gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app
    6. Check the detailed logs in the Azure App Service log stream to identify any specific issues related to the environment or missing dependencies.
    7. Ensure that any necessary environment variables are set correctly in the Azure App Service configuration.

    Note- Check if you are calling the correct Gunicorn using which gunicorn (on Linux, or use where on Powerbash from Windows) from the terminal. If you are using a venv it should print a path pointing inside your venv directory.

    Its not a good way to install using sudo apt install gunicorn. It could be a good option for your production container, where you'll probably run the application without a venv, but in developer mode on you machine it will work better if you install gunicorn inside your venv directory using the pip install gunicorn, using the pip from your venv.

    Then you can call it with python -m gunicorn main:app -k uvicorn.workers.UvicornWorker

    If you have any further assistant, do let me know.

    If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.

    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.