How to Fix ModuleNotFoundError: No module named 'ai_services'

Arnab Mukherjee 95 Reputation points
2025-10-05T09:50:59.6566667+00:00

I am trying to deploy a Fast API python project on Azure App Service (Linux) through the Zip Deployment. It shows build successfull but getting the below error . I have set SCM_DO_BUILD_DURING_DEPLOYMENT to True, but still it is throwing the same error. I am using below command in startup command.

gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

I am unablle to attach the zip folder here so added the image of the project folder structure.
User's image 2025_10_04_10-30-0-155_docker.log
So, I am requuesting to please help me here

2025-10-05T09:10:53.616976921Z  Output is compressed. Extracting it...
2025-10-05T09:10:53.616989275Z  Oryx Version: 0.2.20250709.3, Commit: 0cfb8cb7d114b65e539d2f9ccf9804e87b9966ba, ReleaseTagName: 20250709.3
2025-10-05T09:10:53.618644116Z  Extracting '/home/site/wwwroot/output.tar.gz' to directory '/tmp/8de03eeee89ffba'...
2025-10-05T09:10:56.331937572Z  App path is set to '/tmp/8de03eeee89ffba'
2025-10-05T09:10:57.426625076Z  Writing output script to '/opt/startup/startup.sh'
2025-10-05T09:10:57.734973948Z  Using packages from virtual environment antenv located at /tmp/8de03eeee89ffba/antenv.
2025-10-05T09:10:57.735014247Z  Updated PYTHONPATH to '/opt/startup/app_logs:/tmp/8de03eeee89ffba/antenv/lib/python3.13/site-packages'
2025-10-05T09:10:58.915395069Z  [2025-10-05 09:10:58 +0000] [1111] [INFO] Starting gunicorn 23.0.0
2025-10-05T09:10:58.915995520Z  [2025-10-05 09:10:58 +0000] [1111] [INFO] Listening at: http://0.0.0.0:8000 (1111)
2025-10-05T09:10:58.916018326Z  [2025-10-05 09:10:58 +0000] [1111] [INFO] Using worker: uvicorn.workers.UvicornWorker
2025-10-05T09:10:58.919212161Z  [2025-10-05 09:10:58 +0000] [1112] [INFO] Booting worker with pid: 1112
2025-10-05T09:10:58.940031413Z  [2025-10-05 09:10:58 +0000] [1113] [INFO] Booting worker with pid: 1113
2025-10-05T09:10:58.959761165Z  [2025-10-05 09:10:58 +0000] [1114] [INFO] Booting worker with pid: 1114
2025-10-05T09:10:59.011606376Z  [2025-10-05 09:10:59 +0000] [1115] [INFO] Booting worker with pid: 1115
2025-10-05T09:11:04.388841537Z  [2025-10-05 09:11:04 +0000] [1112] [ERROR] Exception in worker process
2025-10-05T09:11:04.389029632Z  Traceback (most recent call last):
2025-10-05T09:11:04.389296939Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
2025-10-05T09:11:04.389657542Z      worker.init_process()
2025-10-05T09:11:04.389668206Z      ~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.389671592Z    File "/tmp/8de03eeee89ffba/antenv/lib/python3.13/site-packages/uvicorn/workers.py", line 75, in init_process
2025-10-05T09:11:04.389675120Z      super().init_process()
2025-10-05T09:11:04.389678038Z      ~~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.389681030Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 135, in init_process
2025-10-05T09:11:04.389684440Z      self.load_wsgi()
2025-10-05T09:11:04.389687477Z      ~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.389690617Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 147, in load_wsgi
2025-10-05T09:11:04.389694175Z      self.wsgi = self.app.wsgi()
2025-10-05T09:11:04.389697175Z                  ~~~~~~~~~~~~~^^
2025-10-05T09:11:04.389700550Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/base.py", line 66, in wsgi
2025-10-05T09:11:04.389703792Z      self.callable = self.load()
2025-10-05T09:11:04.389706640Z                      ~~~~~~~~~^^
2025-10-05T09:11:04.389729934Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 57, in load
2025-10-05T09:11:04.389733593Z      return self.load_wsgiapp()
2025-10-05T09:11:04.389736837Z             ~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.389739782Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 47, in load_wsgiapp
2025-10-05T09:11:04.389743133Z      return util.import_app(self.app_uri)
2025-10-05T09:11:04.389746706Z             ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
2025-10-05T09:11:04.389750164Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/util.py", line 370, in import_app
2025-10-05T09:11:04.389753560Z      mod = importlib.import_module(module)
2025-10-05T09:11:04.389756957Z    File "/opt/python/3.13.5/lib/python3.13/importlib/__init__.py", line 88, in import_module
2025-10-05T09:11:04.389771186Z      return _bootstrap._gcd_import(name[level:], package, level)
2025-10-05T09:11:04.389773779Z             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-10-05T09:11:04.389776311Z    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2025-10-05T09:11:04.389779138Z    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2025-10-05T09:11:04.389781947Z    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
2025-10-05T09:11:04.389784630Z    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
2025-10-05T09:11:04.389787079Z    File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
2025-10-05T09:11:04.389791267Z    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
2025-10-05T09:11:04.389793845Z    File "/tmp/8de03eeee89ffba/main.py", line 28, in <module>
2025-10-05T09:11:04.389796465Z      from ai_services.llm_services import CustomerAgent
2025-10-05T09:11:04.389798792Z  ModuleNotFoundError: No module named 'ai_services'
2025-10-05T09:11:04.389800855Z  [2025-10-05 09:11:04 +0000] [1112] [INFO] Worker exiting (pid: 1112)
2025-10-05T09:11:04.392078354Z  [2025-10-05 09:11:04 +0000] [1113] [ERROR] Exception in worker process
2025-10-05T09:11:04.392089188Z  Traceback (most recent call last):
2025-10-05T09:11:04.392091354Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
2025-10-05T09:11:04.392093677Z      worker.init_process()
2025-10-05T09:11:04.392095788Z      ~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.392097741Z    File "/tmp/8de03eeee89ffba/antenv/lib/python3.13/site-packages/uvicorn/workers.py", line 75, in init_process
2025-10-05T09:11:04.392099862Z      super().init_process()
2025-10-05T09:11:04.392101658Z      ~~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.392103496Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 135, in init_process
2025-10-05T09:11:04.392105400Z      self.load_wsgi()
2025-10-05T09:11:04.392107448Z      ~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.392109614Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 147, in load_wsgi
2025-10-05T09:11:04.392112052Z      self.wsgi = self.app.wsgi()
2025-10-05T09:11:04.392114196Z                  ~~~~~~~~~~~~~^^
2025-10-05T09:11:04.392116327Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/base.py", line 66, in wsgi
2025-10-05T09:11:04.392118726Z      self.callable = self.load()
2025-10-05T09:11:04.392120565Z                      ~~~~~~~~~^^
2025-10-05T09:11:04.392187276Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 57, in load
2025-10-05T09:11:04.392191235Z      return self.load_wsgiapp()
2025-10-05T09:11:04.475534318Z             ~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.475555684Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 47, in load_wsgiapp
2025-10-05T09:11:04.475558696Z      return util.import_app(self.app_uri)
2025-10-05T09:11:04.475565870Z             ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
2025-10-05T09:11:04.475567862Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/util.py", line 370, in import_app
2025-10-05T09:11:04.475570020Z      mod = importlib.import_module(module)
2025-10-05T09:11:04.475572287Z    File "/opt/python/3.13.5/lib/python3.13/importlib/__init__.py", line 88, in import_module
2025-10-05T09:11:04.475574559Z      return _bootstrap._gcd_import(name[level:], package, level)
2025-10-05T09:11:04.475576499Z             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-10-05T09:11:04.475578615Z    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2025-10-05T09:11:04.475581035Z    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2025-10-05T09:11:04.475583862Z    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
2025-10-05T09:11:04.475585879Z    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
2025-10-05T09:11:04.475587815Z    File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
2025-10-05T09:11:04.475593123Z    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
2025-10-05T09:11:04.475595792Z    File "/tmp/8de03eeee89ffba/main.py", line 28, in <module>
2025-10-05T09:11:04.475598409Z      from ai_services.llm_services import CustomerAgent
2025-10-05T09:11:04.475600895Z  ModuleNotFoundError: No module named 'ai_services'
2025-10-05T09:11:04.475602929Z  [2025-10-05 09:11:04 +0000] [1113] [INFO] Worker exiting (pid: 1113)
2025-10-05T09:11:04.475605299Z  [2025-10-05 09:11:04 +0000] [1114] [ERROR] Exception in worker process
2025-10-05T09:11:04.475607607Z  Traceback (most recent call last):
2025-10-05T09:11:04.475609853Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
2025-10-05T09:11:04.475612570Z      worker.init_process()
2025-10-05T09:11:04.475614848Z      ~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.475617207Z    File "/tmp/8de03eeee89ffba/antenv/lib/python3.13/site-packages/uvicorn/workers.py", line 75, in init_process
2025-10-05T09:11:04.475619868Z      super().init_process()
2025-10-05T09:11:04.475622302Z      ~~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.475624552Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 135, in init_process
2025-10-05T09:11:04.475626984Z      self.load_wsgi()
2025-10-05T09:11:04.475629368Z      ~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.475631710Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 147, in load_wsgi
2025-10-05T09:11:04.475638577Z      self.wsgi = self.app.wsgi()
2025-10-05T09:11:04.475640918Z                  ~~~~~~~~~~~~~^^
2025-10-05T09:11:04.475643192Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/base.py", line 66, in wsgi
2025-10-05T09:11:04.475645729Z      self.callable = self.load()
2025-10-05T09:11:04.475648019Z                      ~~~~~~~~~^^
2025-10-05T09:11:04.475650308Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 57, in load
2025-10-05T09:11:04.475652871Z      return self.load_wsgiapp()
2025-10-05T09:11:04.475655178Z             ~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.475657404Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 47, in load_wsgiapp
2025-10-05T09:11:04.475659749Z      return util.import_app(self.app_uri)
2025-10-05T09:11:04.475661987Z             ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
2025-10-05T09:11:04.475664235Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/util.py", line 370, in import_app
2025-10-05T09:11:04.475666651Z      mod = importlib.import_module(module)
2025-10-05T09:11:04.475668956Z    File "/opt/python/3.13.5/lib/python3.13/importlib/__init__.py", line 88, in import_module
2025-10-05T09:11:04.475671429Z      return _bootstrap._gcd_import(name[level:], package, level)
2025-10-05T09:11:04.475673837Z             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-10-05T09:11:04.475676259Z    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2025-10-05T09:11:04.475678793Z    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2025-10-05T09:11:04.475681723Z    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
2025-10-05T09:11:04.475684171Z    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
2025-10-05T09:11:04.475686582Z    File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
2025-10-05T09:11:04.475689172Z    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
2025-10-05T09:11:04.475691743Z    File "/tmp/8de03eeee89ffba/main.py", line 28, in <module>
2025-10-05T09:11:04.475694295Z      from ai_services.llm_services import CustomerAgent
2025-10-05T09:11:04.475696648Z  ModuleNotFoundError: No module named 'ai_services'
2025-10-05T09:11:04.475699040Z  [2025-10-05 09:11:04 +0000] [1114] [INFO] Worker exiting (pid: 1114)
2025-10-05T09:11:04.702865136Z  [2025-10-05 09:11:04 +0000] [1115] [ERROR] Exception in worker process
2025-10-05T09:11:04.702891981Z  Traceback (most recent call last):
2025-10-05T09:11:04.702895026Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
2025-10-05T09:11:04.702897756Z      worker.init_process()
2025-10-05T09:11:04.703167361Z      ~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.703170921Z    File "/tmp/8de03eeee89ffba/antenv/lib/python3.13/site-packages/uvicorn/workers.py", line 75, in init_process
2025-10-05T09:11:04.703172557Z      super().init_process()
2025-10-05T09:11:04.703174264Z      ~~~~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.703175650Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 135, in init_process
2025-10-05T09:11:04.703177320Z      self.load_wsgi()
2025-10-05T09:11:04.703178623Z      ~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.703179927Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/workers/base.py", line 147, in load_wsgi
2025-10-05T09:11:04.703181405Z      self.wsgi = self.app.wsgi()
2025-10-05T09:11:04.703182811Z                  ~~~~~~~~~~~~~^^
2025-10-05T09:11:04.703184129Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/base.py", line 66, in wsgi
2025-10-05T09:11:04.703185601Z      self.callable = self.load()
2025-10-05T09:11:04.703186895Z                      ~~~~~~~~~^^
2025-10-05T09:11:04.703188288Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 57, in load
2025-10-05T09:11:04.703189717Z      return self.load_wsgiapp()
2025-10-05T09:11:04.703191010Z             ~~~~~~~~~~~~~~~~~^^
2025-10-05T09:11:04.703192307Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/app/wsgiapp.py", line 47, in load_wsgiapp
2025-10-05T09:11:04.703193869Z      return util.import_app(self.app_uri)
2025-10-05T09:11:04.703195252Z             ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
2025-10-05T09:11:04.703196634Z    File "/opt/python/3.13.5/lib/python3.13/site-packages/gunicorn/util.py", line 370, in import_app
2025-10-05T09:11:04.703198141Z      mod = importlib.import_module(module)
2025-10-05T09:11:04.703199499Z    File "/opt/python/3.13.5/lib/python3.13/importlib/__init__.py", line 88, in import_module
2025-10-05T09:11:04.703200938Z      return _bootstrap._gcd_import(name[level:], package, level)
2025-10-05T09:11:04.703202336Z             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-10-05T09:11:04.703203695Z    File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2025-10-05T09:11:04.703205523Z    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2025-10-05T09:11:04.703206942Z    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
2025-10-05T09:11:04.703208436Z    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
2025-10-05T09:11:04.703209822Z    File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
2025-10-05T09:11:04.703212824Z    File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
2025-10-05T09:11:04.703214368Z    File "/tmp/8de03eeee89ffba/main.py", line 28, in <module>
2025-10-05T09:11:04.703218290Z      from ai_services.llm_services import CustomerAgent
2025-10-05T09:11:04.703219744Z  ModuleNotFoundError: No module named 'ai_services'
2025-10-05T09:11:04.703221126Z  [2025-10-05 09:11:04 +0000] [1115] [INFO] Worker exiting (pid: 1115)
2025-10-05T09:11:06.017611555Z  [2025-10-05 09:11:06 +0000] [1111] [ERROR] Worker (pid:1112) exited with code 3
2025-10-05T09:11:06.052811747Z  [2025-10-05 09:11:06 +0000] [1111] [ERROR] Worker (pid:1115) was sent SIGTERM!
2025-10-05T09:11:06.122140853Z  [2025-10-05 09:11:06 +0000] [1111] [ERROR] Worker (pid:1113) was sent SIGTERM!
2025-10-05T09:11:06.123043529Z  [2025-10-05 09:11:06 +0000] [1111] [ERROR] Worker (pid:1114) was sent SIGTERM!
2025-10-05T09:11:06.219922482Z  [2025-10-05 09:11:06 +0000] [1111] [ERROR] Shutting down: Master
2025-10-05T09:11:06.219943602Z  [2025-10-05 09:11:06 +0000] [1111] [ERROR] 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.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Burlachenko 18,575 Reputation points Volunteer Moderator
    2025-10-06T07:57:18.4233333+00:00

    hi

    Your app is building successfully, but when it starts up, Python can't find your ai_services module. This almost always happens because your project structure isn't quite right for how Azure App Service expects to find Python packages.

    The issue is that ai_services is a local folder in your project, but it's not being treated as an installable Python package. When Oryx (the build system) runs, it installs dependencies from requirements.txt, but it doesn't automatically add your local project folders to Python's path.

    Check for requirements.txt: Make sure you have a requirements.txt file in your project root that lists all your dependencies. The build process needs this.

    Make ai_services a proper package: In your ai_services folder, create an empty file named __init__.py. This tells Python that the folder is a package.

    Create a setup.py file (The Key Fix): In your project root, create a setup.py file. This tells Oryx to install your local code as a package.

    from setuptools import setup, find_packages

    setup(

    name="your-app-name",

    packages=find_packages(),

    include_package_data=True,

    install_requires=[

    # List your main dependencies here, or rely on requirements.txt
    

    ],

    )

    Re-deploy: Zip your project again, making sure it includes the new __init__.py and setup.py files, and deploy it.

    The setup.py file is the magic ingredient. It triggers Oryx to run pip install -e ., which installs your local project in "editable" mode, making the ai_services module discoverable.

    regards,

    Alex

    and "yes" if you would follow me at Q&A - personaly thx.
    P.S. If my answer help to you, please Accept my answer
    

    https://ctrlaltdel.blog/


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.