Apache+WSGI Django Docker - Возникает ошибка при запуске Django: RuntimeError: populate() isn't reentrant
Есть такая связка Apache+WSGI Django Docker. При запуске контейнера дефолтная страница Апач открывается нормально. Но при переходе на какие-нибудь страницы с приложением ДЖанго не открывается, а в логах ошибка: Это лог в контейнере
root@828dcbc18f43:/# tail -f /var/log/apache2/error.log
mod_wsgi (pid=9): Failed to exec Python script file '/home/test/app1/backend/otu_it/wsgi.py'.
mod_wsgi (pid=9): Exception occurred processing WSGI script '/home/test/app1/backend/otu_it/wsgi.py'.
Traceback (most recent call last):
File "/home/test/app1/backend/otu_it/wsgi.py", line 20, in <module>
application = get_wsgi_application()
File "/home/test/app1/venv/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/test/app1/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/test/app1/venv/lib/python3.8/site-packages/django/apps/registry.py", line 83, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
А это конфиг файл апача для приложения Django:
WSGIPythonHome /home/test/app1/venv
WSGIPythonPath /home/test/app1/backend
<VirtualHost *:80/api/user>
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /home/test/app1/backend/
WSGIScriptAlias / /home/test/app1/backend/otu_it/wsgi.py
# WSGIPythonHome /home/test/app1/venv
# WSGIPythonPath /home/test/app1/backend
<Directory /home/test/app1/backend/otu_it/>
## NEW
Require all granted
<Files wsgi.py>
Require all granted
</Files>
# Order allow,deny
# Allow from all
</Directory>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/cert.crt
SSLCertificateKeyFile /etc/apache2/ssl/cert.key
ServerAdmin webmaster@localhost
DocumentRoot /home/test/app1/backend/
WSGIScriptAlias / /home/test/app1/backend/otu_it/wsgi.py
# WSGIPythonHome /home/test/app1/venv
# WSGIPythonPath /home/test/app1/backend
<Directory /home/test/app1/backend/otu_it/>
<Files wsgi.py>
Require all granted
</Files>
# Order allow,deny
# Allow from all
</Directory>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Возможно я не верно подключил виртуальную Среду для Джанго. Я уже многое перепробовал - ничего не помогло. В чём может быть проблема? P.S. - Вне контейнера всё работает с этими конфигами без проблем.
После более внимательного изучения логов нашёл вот такие записи:
mod_wsgi (pid=10): Failed to exec Python script file '/home/test/app1/backend/otu_it/wsgi.py'.
mod_wsgi (pid=10): Exception occurred processing WSGI script '/home/test/app1/backend/otu_it/wsgi.py'.
Traceback (most recent call last):
File "/home/test/app1/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
import psycopg as Database
File "/home/test/app1/venv/lib/python3.8/site-packages/psycopg/__init__.py", line 9, in <module>
from . import pq # noqa: F401 import early to stabilize side effects
File "/home/test/app1/venv/lib/python3.8/site-packages/psycopg/pq/__init__.py", line 114, in <module>
import_from_libpq()
File "/home/test/app1/venv/lib/python3.8/site-packages/psycopg/pq/__init__.py", line 106, in import_from_libpq
raise ImportError(
ImportError: no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
- couldn't import psycopg 'python' implementation: libpq library not found
Далее я установил дополнительные модули
pip install psycopg2
pip install psycopg2-binary
И всё заработало.