Getting module not found error in during site startup

Bitthal Ladiwal 20 Reputation points
2025-01-15T08:44:44.41+00:00

I am trying to deploy an azure bot (python-echo-bot) to azure app service using arm templates

https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/02.echo-bot
It build successfully but at the site starting process I get this error (see imageScreenshot 2025-01-15 140608

)

I am using zip file for the deployment, here is the zip file contents

Screenshot 2025-01-15 124324

And no I am not including the root folder in the zip file.
i am zipping the files inside

BotBuilder-Samples\samples\python\02.echo-bot\

Please help, I am stuck.

Edit:

I noticed that the gunicorn container is listening on port 8000 and the app.py bot runs on port 3978.... also the appCommandLine in the botApp template has command - "

gunicorn --bind 0.0.0.0: --worker-class aiohttp.worker.GunicornWebWorker --timeout 600 app:APP

"

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
882 questions
{count} votes

Accepted answer
  1. Sina Salam 16,446 Reputation points
    2025-01-18T12:38:36.9466667+00:00

    Dear Bitthal Ladiwal,

    Thank you for your feedback.

    You will need to ensure compatibility between gunicorn and the bot, and avoids potential pitfalls in deployment. By aligning the file structure, port configurations, and startup command, the bot will deploy successfully to Azure App Service.

    These are the steps you will need to take:

    1. Keep the file structure simple and align it with how gunicorn expects the main module. Place echo_bot.py in the same directory as app.py, and update import statements accordingly.
    2. Set the WEBSITES_PORT to 8000 (the default for gunicorn) in the ARM template:
           {
             "name": "WEBSITES_PORT",
             "value": "8000"
           }
      
      Update config.py (or equivalent configuration file) to use port 8000 instead of 3978: "port": 8000
    3. Modify the gunicorn startup command in the ARM template to explicitly include the port:
         gunicorn --bind 0.0.0.0:8000 --worker-class aiohttp.worker.GunicornWebWorker --timeout 600 app:APP
      
    4. Ensure the requirements.txt file lists all dependencies accurately and check that the app service logs for errors using bash command: az webapp log tail --resource-group <your-resource-group> --name <your-app-name>
    5. This is a "Best Practices" tips: Avoid hardcoding ports in both the gunicorn command and configuration file. Instead, use environment variables:
           import os
           PORT = int(os.environ.get("PORT", 8000))
      
      Make sure the WEBSITES_PORT environment variable is set in your deployment pipeline to match the port defined in the startup command.

    Goodluck.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Sina Salam 16,446 Reputation points
    2025-01-15T16:40:30.0466667+00:00

    Hello Bitthal Ladiwal,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are getting module not found error in during site startup.

    The first thing you might need to look into are missing dependencies or incorrect startup commands, which are common causes of such errors.

    However, these are lists of more specific possible steps, to be able to resolve the "module not found" error and successfully deploy your bot to Azure App Service.

    1. Make sure that all necessary dependencies are listed in the requirements.txt file. This file should be at the root of your zip file.
    2. Check that the file structure inside your zip file is correct. The requirements.txt and your main application file (e.g., app.py or bot.py) should be at the root level of the zip file.
    3. Make sure that the startup command points to the correct entry point of your bot application. For example, if your main file is bot.py, the startup command should be:
         az webapp config set --resource-group <your-resource-group> --name <your-app-name> --startup-file "python3 bot.py"
      
    4. Ensure that your ARM template correctly specifies the deployment settings, including the app service plan, web app, and deployment source. This is an example of how to configure your ARM template:
              {
                "type": "Microsoft.Web/sites",
                "apiVersion": "2021-02-01",
                "name": "<your-app-name>",
                "location": "<your-location>",
                "properties": {
                  "serverFarmId": "<your-app-service-plan>",
                  "siteConfig": {
                    "appSettings": [
                      {
                        "name": "WEBSITES_PORT",
                        "value": "8000"
                      }
                    ]
                  }
                }
              }
      
    5. Check the logs for more detailed error messages. You can access the logs through the Azure portal or using the Azure CLI:
    az webapp log tail --resource-group <your-resource-group> --name <your-app-name>
    

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    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.