How can I install mysqlclient on OSX


As I mainly work with my Mac, I would lime to use Django and I install it on my Mac.

I installed django with the following command

pip3 install -r requierement.txt
here is my requierment file.


I also imported my database with several tables.

Now I run the command ./ inspectdb and I got that error message

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

With ubuntu I easly fix that problem with pip3 install mysqlclient but with Mac , I experienced and issue

pip3 install mysqlclient

Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Preparing metadata ( … error
error: subprocess-exited-with-error

× python egg_info did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File “”, line 2, in
File “”, line 34, in
File “/private/var/folders/g8/w2hfprf12w348r4lmt0y1t1r0000gn/T/pip-install-zjcmmh57/mysqlclient_f1524e83310b41288fe3921681ca7af5/”, line 15, in
metadata, options = get_config()
File “/private/var/folders/g8/w2hfprf12w348r4lmt0y1t1r0000gn/T/pip-install-zjcmmh57/mysqlclient_f1524e83310b41288fe3921681ca7af5/”, line 70, in get_config
libs = mysql_config(“libs”)
File “/private/var/folders/g8/w2hfprf12w348r4lmt0y1t1r0000gn/T/pip-install-zjcmmh57/mysqlclient_f1524e83310b41288fe3921681ca7af5/”, line 31, in mysql_config
raise OSError(“{} not found”.format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
[end of output]

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

How can i fix it with an OSX?

I finally found the solution but I have some difficulties to explain.
I am going to wrote how I did and to provide additional information that I have not write.

On my MAC I use MAMP. After installing MAMP I have a mysql database and myphpamdin.
With the time I do not really like it, but I would like to use something which already exist.
From phpmyadmin, I imported my database with a lot a lot of measure. I woule like to work with that measures.

I installed django and I could not access my database with this settings

    'default': {
        #'ENGINE': 'django.db.backends.sqlite3',
        'ENGINE': 'django.db.backends.mysql',
        #'NAME': BASE_DIR / 'db.sqlite3',
        'NAME': 'db_console',
        'USER': 'console',
        'PASSWORD': 'console',
        'PORT': '8889',

I investigate and that link helped me but it did not solve the problem

After many attends, I did the following with does not make sense
brew install mysql

then I went to my environment and I installed (.env) pip3 install mysqlclient I run ./ inspectdb but I got the error stating it could not connect to the db.
then I changed my settings as the following

    'default': {
        #'ENGINE': 'django.db.backends.sqlite3',
        'ENGINE': 'django.db.backends.mysql',
        #'NAME': BASE_DIR / 'db.sqlite3',
        'NAME': 'db_console',
        'USER': 'console',
        'PASSWORD': 'console',
        'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock',
        #'PORT': '8889',

and hopefully, ./ inspectdb print my models.

It’s nice because now it’s work and I can continue learning django on my mac, but I am a bit suspicious with the command brew install mysql. It’s look like I installed a redundant mysql, isn’t?

At least, it’s work now, but…