How to fix :ModuleNotFoundError: No module named 'project' in an Azure deploy Django site

Cary Hutchinson 20 Reputation points
2023-04-19T16:41:22.61+00:00

I have a Django site that works fine locally but when I Deploy it using MS VS Code, I get a ModuleNotFoundError: No module named 'project' critical error

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,851 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
952 questions
{count} votes

Accepted answer
  1. ajkuma 26,296 Reputation points Microsoft Employee
    2023-04-20T18:09:45.58+00:00

    @Cary Hutchinson , Thanks for posting this question! Apologies for any inconvenience with this.  

    Just to confirm, are you leveraging Azure App Service WebApp or Azure Static WebApps? Possible Causes: Typically, the error occurs -Exception: ModuleNotFoundError: No module named 'module_name'." This error occurs when a Python function app fails to load a Python module.    ModuleNotFoundError will usually present itself where the module/package you’re importing is missing. Either it was never defined in requirements.txt, deployment was done but package installation was never done to produce site-packages, or the library is there and the package installation was done - but it’s dependent on a native library (.so files) that is not available in the container.

    Ultimately, this will always cause the application/container to crash. You may run the following command: pip install django to Django modules / and pip install -r requirements.txt To validate if you’re encountering this scenario, you can check with any of the below methods:

    Note: Make sure App Service Logs are enabled first

    • Log Stream
    • Retrieving logs directly from the Kudu site, or directly view/download via an FTP client
    • Diagnose and Solve Problems -> Application Logs detector, Container Crash detector, or Container Issues detector
    • Try setting ENABLE_ORYX_BUILD = true in app settings
    • Additional info on the app setting document:
      ENABLE_ORYX_BUILD - if true, use the Oryx build system instead of the legacy Kudu system Checkout this article/document for more info : Python on Linux App Service and ModuleNotFoundError
    • For customizing the deployment : Configure a Linux Python app for Azure App Service Kindly let us know how it goes, I'll follow-up with you further.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.