问题
I am looking to set up a simple Django application on Azure App Service (Linux OS) by running an Azure Devops Build and Release pipeline. The application builds and creates a release without a problem.
However when the application has been released it runs into runtime errors.
2019-10-15T09:48:16.161816610Z ModuleNotFoundError: No module named 'django'
I run pip3 install -r requirements.txt
as part of the bash post deployment script, and requirements.txt contains Django but it claims the requirement is already satisfied. Or if I bash into the App Service and run the same command it get the same message with the requirements already being satisfied.
Therefore my question is, why am I receiving a ModuleNotFoundError?
回答1:
This is a very normal issue we would meet during the application runtime. About the issue you are facing, there has different situations need to be considered.
1. If you has virtualenv
, ensure the state of virtualenv
is activated.
With the follow command to activate the virtualenv
:
$ source ./{env-name}/bin/activate
For details info, you can check this doc.
2. Ensure the path of module is correct in Wsgi
file:
For python runtime, it has Python module search path. If you did not specified the module path in Wsgi
file, it will not get and read the Django
module.
In your Wsgi
file, it should has these script:
sys.path.append(<module-path})
If you has specified the path, but still has the issue, please check this blog which described the sibling package.
Here has one detailed blog which about the virtualenv
and package path.
来源:https://stackoverflow.com/questions/58392489/django-module-not-found-on-azure-app-service-azure-devops-cd