Azure App Service (Flask): ModuleNotFoundError: No module named 'run'

isha 1 Reputation point
2021-05-18T16:18:48.257+00:00

Hey,
I'm currently working on my college project and tried deploying my Flask application to Azure App Service. However, I keep running into an error that no module named 'run' (the startup file is run.py in the root folder).
The root directory contains the requirements.txt file as well as run.py.
I am using Github Actions as the build provider. The build completes successfully, i.e. all the modules are being downloaded correctly, but the deployment fails.

I use the following startup command:

   gunicorn --bind=0.0.0.0 --timeout 600 run:app  

Complete logs:

   2021-05-18T12:53:22.997524952Z   
   2021-05-18T12:53:22.997560752Z   _____                                 
   2021-05-18T12:53:22.997567552Z   /  _  \ __________ _________   ____    
   2021-05-18T12:53:22.997581752Z  /  /_\  \___   /  |  \_  __ \_/ __ \   
   2021-05-18T12:53:22.997587552Z /    |    \/    /|  |  /|  | \/\  ___/   
   2021-05-18T12:53:22.997592052Z \____|__  /_____ \____/ |__|    \___  >  
   2021-05-18T12:53:22.997596452Z         \/      \/                  \/   
   2021-05-18T12:53:22.997600652Z   
   2021-05-18T12:53:22.997604452Z A P P   S E R V I C E   O N   L I N U X  
   2021-05-18T12:53:22.997608552Z   
   2021-05-18T12:53:22.997612252Z Documentation: http://aka.ms/webapp-linux  
   2021-05-18T12:53:22.997616252Z Python 3.7.9  
   2021-05-18T12:53:22.997620052Z Note: Any data outside '/home' is not persisted  
   2021-05-18T12:53:23.205563707Z Starting OpenBSD Secure Shell server: sshd.  
   2021-05-18T12:53:23.283939727Z Site's appCommandLine: gunicorn --bind=0.0.0.0 --timeout 600 run:app  
   2021-05-18T12:53:23.285423428Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -bindPort 8000 -userStartupCommand 'gunicorn --bind=0.0.0.0 --timeout 600 run:app'  
   2021-05-18T12:53:23.336032241Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'  
   2021-05-18T12:53:23.339104742Z Could not find operation ID in manifest. Generating an operation id...  
   2021-05-18T12:53:23.339214842Z Build Operation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  
   2021-05-18T12:53:24.163744357Z Oryx Version: 0.2.20210225.2, Commit: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, ReleaseTagName: 20210225.2  
   2021-05-18T12:53:24.638606083Z Writing output script to '/opt/startup/startup.sh'  
   2021-05-18T12:53:25.301612860Z WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.  
   2021-05-18T12:53:25.302387060Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.  
   2021-05-18T12:53:26.135877784Z [2021-05-18 12:53:26 +0000] [35] [INFO] Starting gunicorn 20.0.4  
   2021-05-18T12:53:26.135913684Z [2021-05-18 12:53:26 +0000] [35] [INFO] Listening at: http://0.0.0.0:8000 (35)  
   2021-05-18T12:53:26.135919984Z [2021-05-18 12:53:26 +0000] [35] [INFO] Using worker: sync  
   2021-05-18T12:53:26.135924184Z [2021-05-18 12:53:26 +0000] [38] [INFO] Booting worker with pid: 38  
   2021-05-18T12:53:26.135928284Z [2021-05-18 12:53:26 +0000] [38] [ERROR] Exception in worker process  
   2021-05-18T12:53:26.135932284Z Traceback (most recent call last):  
   2021-05-18T12:53:26.135936284Z   File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker  
   2021-05-18T12:53:26.135940484Z     worker.init_process()  
   2021-05-18T12:53:26.135944284Z   File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process  
   2021-05-18T12:53:26.135960884Z     self.load_wsgi()  
   2021-05-18T12:53:26.135965284Z   File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi  
   2021-05-18T12:53:26.135969384Z     self.wsgi = self.app.wsgi()  
   2021-05-18T12:53:26.135973184Z   File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi  
   2021-05-18T12:53:26.135977084Z     self.callable = self.load()  
   2021-05-18T12:53:26.135980784Z   File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load  
   2021-05-18T12:53:26.135984784Z     return self.load_wsgiapp()  
   2021-05-18T12:53:26.135988584Z   File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp  
   2021-05-18T12:53:26.135992584Z     return util.import_app(self.app_uri)  
   2021-05-18T12:53:26.135996284Z   File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app  
   2021-05-18T12:53:26.136000284Z     mod = importlib.import_module(module)  
   2021-05-18T12:53:26.136003984Z   File "/opt/python/3.7.9/lib/python3.7/importlib/__init__.py", line 127, in import_module  
   2021-05-18T12:53:26.136007984Z     return _bootstrap._gcd_import(name[level:], package, level)  
   2021-05-18T12:53:26.136012484Z   File "", line 1006, in _gcd_import  
   2021-05-18T12:53:26.136017084Z   File "", line 983, in _find_and_load  
   2021-05-18T12:53:26.136021084Z   File "", line 965, in _find_and_load_unlocked  
   2021-05-18T12:53:26.136025084Z ModuleNotFoundError: No module named 'run'  
   2021-05-18T12:53:26.136029084Z [2021-05-18 12:53:26 +0000] [38] [INFO] Worker exiting (pid: 38)  
   2021-05-18T12:53:26.216758106Z [2021-05-18 12:53:26 +0000] [35] [INFO] Shutting down: Master  
   2021-05-18T12:53:26.217610206Z [2021-05-18 12:53:26 +0000] [35] [INFO] Reason: Worker failed to boot.  

**Project Structure **(Used made-up names of local modules):

   |-- GithubRepo  
        |--- run.py   
        |--- requirements.txt       
        |--- app  
            |--- __init__.py  
            |--- module1.py  
            |--- module2.py  
            |--- templates  
            |--- static  

run.py

   from app import app  

   if __name__ == "__main__":  
       app.run(debug=True)  

__init__.py:

   app = Flask(__name__)  
   cors = CORS(app)  
   app.config['CORS_HEADERS'] = 'Access-Control-Allow-Origin'  

Other important facts about the project:

  • App Service Plan Tier: Basic B1 Plan
  • Code Source: Github
  • Build Provider: Github Actions
  • I used Git LFS to upload a 1 GB ML model on GitHub
  • SCM_DO_BUILD_DURING_DEPLOYMENT is true

Any help would be appreciated.
Thanks!

EDIT 19-05-2021

Github Workflow .yml file:

   name: Build and deploy Python app to Azure Web App - disaster-response  

   on:  
     push:  
       branches:  
         - runpy  
     workflow_dispatch:  

   jobs:  
     build:  
       runs-on: ubuntu-latest  

       steps:  
       - uses: actions/checkout@v2  

       - name: Set up Python version  
         uses: actions/setup-python@v1  
         with:  
           python-version: '3.7'  

       - name: Create and start virtual environment  
         run: |  
           python -m venv venv  
           source venv/bin/activate  
       - name: Install dependencies  
         run: pip install -r requirements.txt  

       # Optional: Add step to run tests here (PyTest, Django test suites, etc.)  

       - name: Upload artifact for deployment jobs  
         uses: actions/upload-artifact@v2  
         with:  
           name: python-app  
           path: |  
             .  
             !venv/  
     deploy:  
       runs-on: ubuntu-latest  
       needs: build  
       environment:  
         name: 'production'  
         url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}  

       steps:  
         - name: Download artifact from build job  
           uses: actions/download-artifact@v2  
           with:  
             name: python-app  
             path: .  

         - name: 'Deploy to Azure Web App'  
           uses: azure/webapps-deploy@v2  
           with:  
             app-name: 'disaster-response'  
             slot-name: 'production'  
             publish-profile: ${{ secrets.xxxxxxxxxxxxxxx_xxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }}  

Kudu Project Structure:
97780-kudu-dashboard.jpg

97881-index-of-wwwroot.jpg

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

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

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.