Я развертываю приложение Django на экземпляре AWS (amazon2 64-bit, Linux / 4.14.128-112.105.amzn2.x86_64). Я потратил много времени на поиск и поиск переполнения стека, не найдя решения.
Моя проблема: правильно установить mysqlclient.
Ошибка:
mod_wsgi (pid=14418): Failed to exec Python script file '/var/www/html/project_x/project_x/wsgi.py'.
mod_wsgi (pid=14418): Exception occurred processing WSGI script '/var/www/html/project_x/project_x/wsgi.py'.
Traceback (most recent call last):
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: cannot import name '_mysql'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/var/www/html/project_x/project_x/wsgi.py", line 17, in <module>
application = get_wsgi_application()
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 20, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Я установил все, но это не работает.
Я создал виртуальную среду внутри папки проектов:
$ virtualenv projectenv --python=python3.7
$ source projectenv/bin/activate
После этого я установил плагины с pip:
$ pip list
Package Version
----------- -------
Django 2.2.5
mysqlclient 1.4.4
pip 19.2.3
pytz 2019.2
setuptools 41.2.0
sqlparse 0.3.0
wheel 0.33.6
Как выможно увидеть, пакеты установлены правильно. Также установлен msqlclient. Я не знаю, что еще делать, я просмотрел много сообщений о Stackoverflow, но ни одна из них не решила мою проблему.