virtualenv(python3.4), pip install mysqlclient error

Try to run this before:

Ubuntu:

sudo apt-get install python-dev python3-dev
sudo apt-get install libmysqlclient-dev
pip install pymysql
pip install mysqlclient

In OSX:

sudo xcodebuild -license accept
brew install mysql-connector-c

This is probably due to your mysql_config being broken.

As of 2019, here is how to run smoothly pip install mysqlclient on MacOS:

brew info openssl and follow the commands at the bottom

  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

Other approaches:

  • brew install/upgrade/reinstall mysql : did not fix the issue for me, but has the nice side effect to make sure your installation is clean.
  • brew install mysql-connector-c : to make that work you have to unlink mysql, which ruins your setup and it did not fix the issue for me.