Мое приложение django нормально работает на моем экземпляре ubuntu ec2, Apache2 + mod_wsgi и базе данных Mysql, работающей на том же экземпляре. Я решил переключиться на отдельную базу данных postgres RDS, но когда я пытаюсь использовать эту базу данных, я получаю Apache «Внутренняя ошибка сервера» и следующие ошибки wsgi в моем файле Apache error.log.
Если я переключаюсь на базу данных Mysql в своем файле settings.py, веб-сайт все еще работает. Ошибка возникает только тогда, когда я просто отдельную базу данных postgres. Я использую Django 2.2 с python3.7
Конфигурация Apache:
<IfModule mod_ssl.c>
<VirtualHost *:443>
...
Alias /static /home/ubuntu/ratemanager/Projects/static
<Directory /home/ubuntu/ratemanager/Projects/static>
Require all granted
</Directory>
<Directory /home/ubuntu/ratemanager/Projects/Projects>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/ubuntu/ratemanager/Projects/Projects/wsgi.py
WSGIDaemonProcess django_app python-path=/home/ubuntu/ratemanager/Projects python-home=/home/ubuntu/ratemanager/Projects/venv
WSGIProcessGroup django_app
SSLCertificateFile /etc/letsencrypt/live/...
SSLCertificateKeyFile /etc/letsencrypt/...
Include /etc/letsencrypt/options-ssl-apache.conf
error.log
[core:notice] AH00094: Command line: '/usr/sbin/apache2'
[wsgi:error] mod_wsgi (pid=27601): Target WSGI script '/home/ubuntu/ratemanager/Projects/Projects/wsgi.py' cannot be loaded as Python module.
[wsgi:error] mod_wsgi (pid=27601): Exception occurred processing WSGI script '/home/ubuntu/ratemanager/Projects/Projects/wsgi.py'.
[wsgi:error] Traceback (most recent call last):
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 20, in <module>
[wsgi:error] import psycopg2 as Database
[wsgi:error] ModuleNotFoundError: No module named 'psycopg2'
[wsgi:error]
[wsgi:error] During handling of the above exception, another exception occurred:
[wsgi:error]
[wsgi:error] Traceback (most recent call last):
[wsgi:error] File "/home/ubuntu/ratemanager/Projects/Projects/wsgi.py", line 15, in <module>
[wsgi:error] application = get_wsgi_application()
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[wsgi:error] django.setup(set_prefix=False)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
[wsgi:error] apps.populate(settings.INSTALLED_APPS)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 112, in populate
[wsgi:error] app_config.import_models()
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 198, in import_models
[wsgi:error] self.models_module = import_module(models_module_name)
[wsgi:error] File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
[wsgi:error] return _bootstrap._gcd_import(name[level:], package, level)
[wsgi:error] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[wsgi:error] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[wsgi:error] File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
[wsgi:error] File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
[wsgi:error] File "<frozen importlib._bootstrap_external>", line 678, in exec_module
[wsgi:error] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[wsgi:error] File "/home/ubuntu/ratemanager/Projects/RateManager/models.py", line 2, in <module>
[wsgi:error] from django.contrib.auth.models import User
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/models.py", line 2, in <module>
[wsgi:error] from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/base_user.py", line 47, in <module>
[wsgi:error] class AbstractBaseUser(models.Model):
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 101, in __new__
[wsgi:error] new_class.add_to_class('_meta', Options(meta, app_label))
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 305, in add_to_class
[wsgi:error] value.contribute_to_class(cls, name)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/models/options.py", line 203, in contribute_to_class
[wsgi:error] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/__init__.py", line 33, in __getattr__
[wsgi:error] return getattr(connections[DEFAULT_DB_ALIAS], item)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 202, in __getitem__
[wsgi:error] backend = load_backend(db['ENGINE'])
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 110, in load_backend
[wsgi:error] return import_module('%s.base' % backend_name)
[wsgi:error] File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
[wsgi:error] return _bootstrap._gcd_import(name[level:], package, level)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 24, in <module>
[wsgi:error] raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[wsgi:error] django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
[wsgi:error] mod_wsgi (pid=27601): Target WSGI script '/home/ubuntu/ratemanager/Projects/Projects/wsgi.py' cannot be loaded as Python module.
[wsgi:error] mod_wsgi (pid=27601): Exception occurred processing WSGI script '/home/ubuntu/ratemanager/Projects/Projects/wsgi.py'.
[wsgi:error] Traceback (most recent call last):
[wsgi:error] File "/home/ubuntu/ratemanager/Projects/Projects/wsgi.py", line 15, in <module>
[wsgi:error] application = get_wsgi_application()
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[wsgi:error] django.setup(set_prefix=False)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
[wsgi:error] apps.populate(settings.INSTALLED_APPS)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 81, in populate
[wsgi:error] raise RuntimeError("populate() isn't reentrant")
[wsgi:error] RuntimeError: populate() isn't reentrant
[wsgi:error] mod_wsgi (pid=27601): Target WSGI script '/home/ubuntu/ratemanager/Projects/Projects/wsgi.py' cannot be loaded as Python module.
[wsgi:error] mod_wsgi (pid=27601): Exception occurred processing WSGI script '/home/ubuntu/ratemanager/Projects/Projects/wsgi.py'.
[wsgi:error] Traceback (most recent call last):
[wsgi:error] File "/home/ubuntu/ratemanager/Projects/Projects/wsgi.py", line 15, in <module>
[wsgi:error] application = get_wsgi_application()
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[wsgi:error] django.setup(set_prefix=False)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
[wsgi:error] apps.populate(settings.INSTALLED_APPS)
[wsgi:error] File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 81, in populate
[wsgi:error] raise RuntimeError("populate() isn't reentrant")
[wsgi:error] RuntimeError: populate() isn't reentrant
[mpm_event:notice] AH00491: caught SIGTERM, shutting down
[mpm_event:notice] AH00489: Apache/2.4.29 (Ubuntu) OpenSSL/1.1.0g mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[core:notice] AH00094: Command line: '/usr/sbin/apache2'
Любая помощь будет оценена. Я перепробовал многие решения, которые нашел в Интернете, и не могу заставить это работать.
sudo apt-get install python3.7-dev позволил мне установить psycopg2, но я все еще получаю вышеуказанные ошибки