Python web app not working on Python 3.9

Shengyu Fu 1 Reputation point
2021-10-19T18:48:53.84+00:00

Deploy python app using: https://github.com/MusicAsLanguage/webservice/blob/main/.github/workflows/workflow.yml
Failed to start the app with following error:
2021-10-15T00:01:18.292517819Z
2021-10-15T00:01:18.292569720Z _____
2021-10-15T00:01:18.292575320Z / _ \ __________ _________ ____
2021-10-15T00:01:18.292579520Z / /_\ ___ / | _ __ _/ __ \
2021-10-15T00:01:18.292583520Z / | / /| | /| | /\ /
2021-10-15T00:01:18.292587420Z _
|__ /_____ ____/ || _ >
2021-10-15T00:01:18.292591420Z / / /
2021-10-15T00:01:18.292595420Z
2021-10-15T00:01:18.292598820Z A P P S E R V I C E O N L I N U X
2021-10-15T00:01:18.292602520Z
2021-10-15T00:01:18.292606820Z Documentation: http://aka.ms/webapp-linux
2021-10-15T00:01:18.292610420Z Python 3.7.9
2021-10-15T00:01:18.292614020Z Note: Any data outside '/home' is not persisted
2021-10-15T00:01:18.585790988Z Starting OpenBSD Secure Shell server: sshd.
2021-10-15T00:01:18.661016393Z App Command Line not configured, will attempt auto-detect
2021-10-15T00:01:18.662229201Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -bindPort 8000
2021-10-15T00:01:18.705934495Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2021-10-15T00:01:18.708324711Z Build Operation ID: |Z5gNBfqZA0c=.d7e8c563_
2021-10-15T00:01:18.709165116Z Oryx Version: 0.2.20210708.1, Commit: 6ceb6608673b94827bac111ef5ea01c216f92abb, ReleaseTagName: 20210708.1
2021-10-15T00:01:19.491843570Z Detected an app based on Flask
2021-10-15T00:01:19.495768996Z Generating gunicorn command for 'app:app'
2021-10-15T00:01:20.424703332Z Writing output script to '/opt/startup/startup.sh'
2021-10-15T00:01:21.487912969Z Using packages from virtual environment pythonenv3.9 located at /home/site/wwwroot/pythonenv3.9.
2021-10-15T00:01:21.488874875Z Updated PYTHONPATH to ':/home/site/wwwroot/pythonenv3.9/lib/python3.7/site-packages'
2021-10-15T00:01:22.274390449Z [2021-10-15 00:01:22 +0000] [38] [INFO] Starting gunicorn 20.1.0
2021-10-15T00:01:22.281751599Z [2021-10-15 00:01:22 +0000] [38] [INFO] Listening at: http://0.0.0.0:8000 (38)
2021-10-15T00:01:22.282501914Z [2021-10-15 00:01:22 +0000] [38] [INFO] Using worker: sync
2021-10-15T00:01:22.293326435Z [2021-10-15 00:01:22 +0000] [41] [INFO] Booting worker with pid: 41
2021-10-15T00:01:22.836603206Z [2021-10-15 00:01:22 +0000] [41] [ERROR] Exception in worker process
2021-10-15T00:01:22.836636107Z Traceback (most recent call last):
2021-10-15T00:01:22.836641607Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-10-15T00:01:22.836646107Z worker.init_process()
2021-10-15T00:01:22.836649907Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-10-15T00:01:22.836673107Z self.load_wsgi()
2021-10-15T00:01:22.836677808Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-10-15T00:01:22.836681908Z self.wsgi = self.app.wsgi()
2021-10-15T00:01:22.836685808Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-10-15T00:01:22.836689808Z self.callable = self.load()
2021-10-15T00:01:22.836693608Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-10-15T00:01:22.836697708Z return self.load_wsgiapp()
2021-10-15T00:01:22.836701408Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-10-15T00:01:22.836705508Z return util.import_app(self.app_uri)
2021-10-15T00:01:22.836709308Z File "/opt/python/3.7.9/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
2021-10-15T00:01:22.836713408Z mod = importlib.import_module(module)
2021-10-15T00:01:22.836717308Z File "/opt/python/3.7.9/lib/python3.7/importlib/init.py", line 127, in import_module
2021-10-15T00:01:22.836721308Z return _bootstrap._gcd_import(name[level:], package, level)
2021-10-15T00:01:22.836725209Z File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
2021-10-15T00:01:22.836729709Z File "<frozen importlib._bootstrap>", line 983, in _find_and_load
2021-10-15T00:01:22.836733709Z File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
2021-10-15T00:01:22.836737709Z File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
2021-10-15T00:01:22.836741709Z File "<frozen importlib._bootstrap_external>", line 728, in exec_module
2021-10-15T00:01:22.836745909Z File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-10-15T00:01:22.836750009Z File "/home/site/wwwroot/app.py", line 2, in <module>
2021-10-15T00:01:22.836754109Z from flask_bcrypt import Bcrypt
2021-10-15T00:01:22.836758009Z ModuleNotFoundError: No module named 'flask_bcrypt'
2021-10-15T00:01:22.842247421Z [2021-10-15 00:01:22 +0000] [41] [INFO] Worker exiting (pid: 41)
2021-10-15T00:01:23.021457973Z [2021-10-15 00:01:23 +0000] [38] [INFO] Shutting down: Master
2021-10-15T00:01:23.022868802Z [2021-10-15 00:01:23 +0000] [38] [INFO] Reason: Worker failed to boot.

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

2 answers

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2021-10-20T03:01:26.387+00:00

    Your app failed due to ModuleNotFoundError: No module named 'flask_bcrypt'. Make sure SCM_DO_BUILD_DURING_DEPLOYMENT added to your application settings and set to 1, see https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#modulenotfounderror-when-app-starts. This will tell your app service to install the modules listed in your requirements.txt.

    0 comments No comments

  2. SnehaAgrawal-MSFT 22,706 Reputation points Moderator
    2021-10-20T03:09:11.62+00:00

    Thanks for asking question! As I can see error ModuleNotFoundError: No module named 'flask_bcrypt' this means that Python could not find one or more of your modules when the application started.

    This most often occurs if you deploy your virtual environment with your code. Virtual environments are not portable, so a virtual environment should not be deployed with your application code. Instead, let Oryx create a virtual environment and install your packages on the web app.

    Could you go to your web app through Azure portal > Configurations > Application settings > add New Application setting > add name = SCM_DO_BUILD_DURING_DEPLOYMENT and value to 1 > Ok and then Save.

    141916-webapp-microsoft-azure.png

    This will force Oryx to install your packages whenever you deploy to App Service.

    For more information, please see this article on virtual environment portability.

    Let us know if further query or issue remains.

    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.