Thursday, 28 April 2016

Python: Install MySQLdb on MAC OS

Prerequisite
Make sure you installed MySQL.

Step 1: Install PIP, if you don’t install. Following post explains you how to install PIP.

Step 2: Run following command to install MySQL.

pip install MySQL-python
# pip install MySQL-python
Collecting MySQL-python
  Using cached MySQL-python-1.2.5.zip
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python
Successfully installed MySQL-python-1.2.5

Step 3: Create symbolic link.
ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib


Step 4: Open new terminal. Open python prompt and type ‘import MySQLdb’.
$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import MySQLdb
>>>


If you don’t get any error, you successfully installed MySQLdb. If MySQLdb is not installed properly, you will get following error.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'MySQLdb'


Note:
1. If you got any error, try reinstalling after exporting the path like below

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



Previous                                                 Next                                                 Home

No comments:

Post a Comment