Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install MySQLdb on Mountain Lion

I'm new to Python and I'm having trouble building MySQLdb, in an attempt to get Google AppEngine SDK running. I have just upgraded from Snow Leopard to Mountain Lion and have installed the latest XCode (4.4)

I've downloaded http://sourceforge.net/projects/mysql-python/

python setup.py build 

i get the following output in terminal

running build
running build_py
creating build
creating build/lib.macosx-10.8-intel-2.7
copying _mysql_exceptions.py -> build/lib.macosx-10.8-intel-2.7
creating build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
creating build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.8-intel-    2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.8-intel-2.7
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.8-intel-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
unable to execute clang: No such file or directory
error: command 'clang' failed with exit status 1

both of the following directories exist, i have no idea how to resolve the issue with clang not being able to execute...

/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
/usr/local/mysql/include
like image 339
Darragh McCarthy Avatar asked Aug 02 '12 22:08

Darragh McCarthy


2 Answers

It seems that the system is complaining about not be able to find clang, which is included in Command Line Tools of Xcode. Did you installed the tool as well?

Can be installed via

  • Open Xcode
  • Preference (Command + ,)
  • Components under the Download tab
like image 134
clwen Avatar answered Oct 10 '22 20:10

clwen


If someone is interested in a quick and easy way for Mac OS X 10.8:

I assume you have XCode, it's command line tool, Python and MySQL installed.

  1. Install PIP:

    sudo easy_install pip
    
  2. Edit ~/.profile:

    nano ~/.profile
    

    Copy and paste the following two line

    export PATH=/usr/local/mysql/bin:$PATH
    export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
    

    Save and exit. Afterwords execute the following command

    source  ~/.profile
    
  3. Install MySQLdb

    sudo pip install MySQL-python
    

    To test if everything works fine just try

    python -c "import MySQLdb"
    

It worked like a charm for me. I hope it helps.

like image 42
F Lekschas Avatar answered Oct 10 '22 22:10

F Lekschas