1

I need to install MySQL-python through (pip install MySQL-python) on Mac due to this import error:

ImportError: No module named MySQLdb

But there is this error during pip install MySQL-python:

running build_ext
building '_mysql' extension
creating build/temp.macosx-10.14-intel-2.7
cc -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes 
-Qunused-arguments -Qunused-arguments -arch i386 
-arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) 
-D__version__=1.2.5 -I/usr/local/opt/mysql-client/include/mysql 
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
-c _mysql.c -o build/temp.macosx-10.14-intel-2.7/_mysql.o
_mysql.c:44:10: fatal error: 'my_config.h' file not found
#include "my_config.h"
         ^~~~~~~~~~~~~
1 error generated.
error: command 'cc' failed with exit status 1

I tried different solutions provided by Stackoverflow such as: "'cc' failed with exit status 1" error when install python library or command 'cc' failed with exit status 1 on OSX High Sierra but still getting the same error. Any suggestions or comments to resolve this?

Further info:

 (virt-env) m-c0:fz$ which python
   /usr/bin/python
 (virt-env) m-c0:fz$ which pip
  /usr/local/bin/pip
 (virt-env) m-c0:fz$ python --version
  Python 2.7.16

  export PATH="/usr/local/opt/cython/bin:$PATH"
  export PATH="/Users/zf/Library/Python/2.7/bin:$PATH"
  export PATH=$PATH:/usr/local/Cellar/mysql/8.0.18_1/bin
  export PATH="/usr/local/opt/mysql-client/bin:$PATH"
  export CFLAGS=-Qunused-arguments
  export CPPFLAGS=-Qunused-arguments
Alan
  • 417
  • 1
  • 7
  • 22

1 Answers1

1

You don't have mysql C libraries installed on your Mac OS, there are multiple options to install it.

You can install it easy fi you have brew installed on your Mac OS, or google for other options to install the libs using your env.

More info

Alexandr Shurigin
  • 3,921
  • 1
  • 13
  • 25
  • 1
    followed the steps on this link: https://ruddra.com/posts/install-mysqlclient-macos/ and it's resolved! THANKS! – Alan Dec 09 '19 at 04:15
  • The link is no longer available, do you still have the steps? – JohnnyHuo May 13 '21 at 07:26
  • https://medium.com/@MrWeeble/homebrew-on-mac-and-pythons-mysqlclient-ea44fa300e70 this link helps! Short answer, run "env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient==1.3.12" – JohnnyHuo May 13 '21 at 07:48