Security, Tech & Programming
pip install Flask_mysqldb not working on mac

pip install Flask_mysqldb not working on mac

This post will help you fix the issue of pip or pip3 install not working for flask_mysqldb.

The error might include that:

pip install flask_mysqldb
Collecting flask_mysqldb
  Using cached Flask-MySQLdb-0.2.0.tar.gz (2.1 kB)
Collecting Flask>=0.10
  Using cached Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting mysqlclient
  Using cached mysqlclient-1.4.6.tar.gz (85 kB)
    ERROR: Command errored out with exit status 1:
     command: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/ -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/'"'"'; __file__='"'"'/private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);'"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-pip-egg-info-0D9Xsz
         cwd: /private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/
    Complete output (12 lines):
    sh: mysql_config: command not found
    sh: mariadb_config: command not found
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/", line 16, in <module>
        metadata, options = get_config()
      File "", line 61, in get_config
        libs = mysql_config("libs")
      File "", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    EnvironmentError: mysql_config not found
ERROR: Command errored out with exit status 1: python egg_info Check the logs for full command output.


Step 1: is to install brew if you don’t have it on your mac. Install it from brew official website: or by running this command (copied from their website):

/bin/bash -c "$(curl -fsSL"

You might have to close the terminal and launch again to make brew work after fresh install, otherwise it will give an error brew: command not found even when brew is installed.

Step 2: Install mysql

brew install mysql

Step 3: unlink mysql:

brew unlink mysql

Step 4: install mysql-connector-c

brew install mysql-connector-c

Step 5: Add mysql bin folder to PATH

Note: Make sure that the mysql folder with version number is correct, 8.0.11 in this example.

export PATH=/usr/local/Cellar/mysql/8.0.11/bin:$PATH

Step 6: Create required folders:

sudo mkdir /usr/local/Cellar/lib
# if it fails with "No such file or directory"
# create the Cellar folder first by:
sudo mkdir /usr/local/Cellar
# and then run the first command again
sudo mkdir /usr/local/Cellar/lib

Step 7: Create a symlink

Again, make sure that the folder name with mysql version number is correct, here 8.0.11

sudo ln -s /usr/local/Cellar/mysql/8.0.11/lib/libmysqlclient.21.dylib /usr/local/Cellar/lib/libmysqlclient.21.dylib

Step 8: Reinstall openssl

brew reinstall openssl

Step 9: Link mysql again:

brew link mysql

Step 10: Reinstall mysql-client (or anything else that was giving error

LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysqlclient
# or
pip3 install flask_mysqldb

Leave a Reply

Your email address will not be published. Required fields are marked *

Hire Me!