Currently containerizing a legacy Django project, and running into an odd error.
When pushing the config file to the running server, it fails to apply, and on inspecting the log, I get the following:
2023/12/06 21:36:02 [info] 39#39 discovery started
2023/12/06 21:36:02 [notice] 39#39 module: python 3.11.2 "/usr/lib/unit/modules/python3.11.unit.so"
2023/12/06 21:36:02 [info] 1#1 controller started
2023/12/06 21:36:02 [notice] 1#1 process 39 exited with code 0
2023/12/06 21:36:02 [info] 41#41 router started
2023/12/06 21:36:02 [info] 41#41 OpenSSL 3.0.11 19 Sep 2023, 300000b0
2023/12/06 21:40:22 [info] 49#49 "myapp" prototype started
2023/12/06 21:40:22 [info] 50#50 "myapp" application started
2023/12/06 21:40:22 [alert] 50#50 Python failed to import module "myapp.wsgi"
Traceback (most recent call last):
File "/app/myapp/wsgi.py", line 5, in <module>
from django.core.wsgi import get_wsgi_application # noqa: E402
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'django'
2023/12/06 21:40:22 [notice] 49#49 app process 50 exited with code 1
2023/12/06 21:40:22 [warn] 41#41 failed to start application "myapp"
2023/12/06 21:40:22 [alert] 41#41 failed to apply new conf
2023/12/06 21:40:22 [notice] 1#1 process 49 exited with code 0
My config file is as follows:
{
"applications": {
"myapp": {
"type": "python 3.11",
"module": "myapp.wsgi",
"processes": 150,
"environment": {
"DJANGO_SETTINGS_MODULE": "myapp.settings.production",
}
}
},
"listeners": {
"0.0.0.0:8000": {
"pass": "applications/myapp"
}
}
}
Swapping out unit for Gunicorn results in the expected behavior, as well as running the Django development server.
I did notice the version of Python 3 the nginx-unit module is using slightly differs from the one i have installed in the container(Python 3.11.2 vs Python 3.11.7), but don’t see why this would cause this specific issue.
Is nginx-unit having problems locating my Python paths?
Thanks
2
Answers
Fixed this issue by pulling from the official
unit:python3.11
image instead of pulling from the regularpython 3.11
image I had been previous and manually installing unit.Maybe your container does not have django installed? Did you create an environment, install django to it and then activate it? It is not sufficient to
pip install uwsgi
.