ModuleNotFoundError on AWS lightsail for WSGI (SOLVED)

I created a Django instance in AWS lightsail. I went through this tutorial: https://aws.amazon.com/getting-started/hands-on/deploy-python-application/
I did not use the tutorial django project from the tutorial, I used my own django project

Django running with WSGI on Apache gives me the error:

No module named 'statistics.models_es'; 'statistics' is not a package

statistics is one of the apps in my project. My project folder does not seem to be in the paths where django is looking for apps.

I have the line

sys.path.append('/opt/bitnami/apps/django/django_projects/my_app')

in my wsgi.py

When I execute python3 manage.py shell and then execute the line from statistics.models_es import StatisticsClick, everything works fine.

Does somebody have an idea what goes wrong with adding the path to wsgi / apache?

Thank you!

Ok, found the problem:

I had to replace the sys.path.append in my wsgi.py with

sys.path.insert(0, '/opt/bitnami/apps/django/django_projects/my_app')

There seems to be another package named “statistics”.

Maybe this should be changed in the tutorial at https://aws.amazon.com/getting-started/hands-on/deploy-python-application/

Found the solution here:
https://stackoverflow.com/questions/2324219/deploying-django-with-wsgi-app-import-error

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.