Django, mySQL, macOS

На моем мак установлен mysql с официального сайта, я мно работал с ним в процессе обучения через dbeaver, никаких проблем не наблюдалось. Теперь когда я начал изучать фремворк Django я хочу подключать свой проект к mysql (локально). Конфигурация в проекте

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'Django',
        'HOST': 'localhost',
        'PASSWORD': 'my_password',
        'PORT': '3306',
        'USER': 'root'
    }
}

Но при создании нового приложения с помощью python3 manage.py startapp my_app (все запускается из правильной папки проекта) на выводе текст

Traceback (most recent call last): File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/db/backends/mysql/base.py", line 16, in import MySQLdb as Database ModuleNotFoundError: No module named 'MySQLdb'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Users/4izhyk/Documents/Python/Django/movie_project/manage.py", line 22, in main() File "/Users/4izhyk/Documents/Python/Django/movie_project/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/core/management/init.py", line 442, in execute_from_command_line utility.execute() File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/core/management/init.py", line 416, in execute django.setup() File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/apps/registry.py", line 116, in populate app_config.import_models() File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/apps/config.py", line 269, in import_models self.models_module = import_module(models_module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in _load_unlocked
File "", line 999, in exec_module File "", line 488, in _call_with_frames_removed File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/contrib/auth/models.py", line 5, in from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/contrib/auth/base_user.py", line 40, in class AbstractBaseUser(models.Model): File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/db/models/base.py", line 143, in new new_class.add_to_class("_meta", Options(meta, app_label)) File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/db/models/base.py", line 371, in add_to_class value.contribute_to_class(cls, name) File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/db/models/options.py", line 231, in contribute_to_class self.db_table, connection.ops.max_name_length() ^^^^^^^^^^^^^^ File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/utils/connection.py", line 15, in getattr return getattr(self._connections[self._alias], item) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/utils/connection.py", line 62, in getitem conn = self.create_connection(alias) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/db/utils.py", line 193, in create_connection backend = load_backend(db["ENGINE"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/db/utils.py", line 113, in load_backend return import_module("%s.base" % backend_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/django/db/backends/mysql/base.py", line 18, in raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?

Как я понял он не может использовать mysqlclient Нашел что нужно установить дополнителный модуль

pip install mysqlclient

Но и здесь получаю текс с ошибкой

Collecting mysqlclient Using cached mysqlclient-2.2.6.tar.gz (91 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [33 lines of output] /bin/sh: pkg-config: command not found /bin/sh: pkg-config: command not found /bin/sh: pkg-config: command not found /bin/sh: pkg-config: command not found Trying pkg-config --exists mysqlclient Command 'pkg-config --exists mysqlclient' returned non-zero exit status 127. Trying pkg-config --exists mariadb Command 'pkg-config --exists mariadb' returned non-zero exit status 127. Trying pkg-config --exists libmariadb Command 'pkg-config --exists libmariadb' returned non-zero exit status 127. Trying pkg-config --exists perconaserverclient Command 'pkg-config --exists perconaserverclient' returned non-zero exit status 127. Traceback (most recent call last): File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in main() File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/4izhyk/Documents/Python/Django/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) ^^^^^^^^^^^^^^^^^^^^^ File "/private/var/folders/1w/st75q7td5v91z_w064jbltlc0000gn/T/pip-build-env-0jenqrxn/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/var/folders/1w/st75q7td5v91z_w064jbltlc0000gn/T/pip-build-env-0jenqrxn/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires self.run_setup() File "/private/var/folders/1w/st75q7td5v91z_w064jbltlc0000gn/T/pip-build-env-0jenqrxn/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, in run_setup exec(code, locals()) File "", line 155, in File "", line 49, in get_config_posix File "", line 28, in find_package_name Exception: Can not find valid pkg-config name. Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Как же подружить mysql и django? Использую django 5, mysql 9.0.1, macOS 12.7, python 3.12.8

Вернуться на верх