Installing MySQLdb on Mac OS X
Getting MySQLdb, a Python data access library for MySQL, up and running on Mac OS X can be a challenging task. Here's a comprehensive guide to overcome the common obstacles and ensure a smooth installation:
Note for Python 3 Users:
Use conda install mysqlclient to install the necessary libraries. This will install mysqlclient, mysql-connector, and llvmdev.
For Previous Mac OS X Versions:
-
Install 32-bit MySQL: Uninstall any 64-bit versions and obtain the 32-bit package instead.
-
Obtain and Extract MySQLdb: Download the latest MySQLdb package from SourceForge and extract the contents.
-
Clean the Installation: Run "sudo python setup.py clean" within the extracted folder.
-
Remove Old Files: Delete any remnants in the MySQL-python-1.2.2/build/ directory and remove the egg under Users/$USER/.python-eggs.
-
Create Symbolic Link: Execute "sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql" to establish a link to the mysql sub-directory.
-
Edit setup_posix.py: Change "mysql_config.path = 'mysql_config'" to "mysql_config.path = '/usr/local/mysql/bin/mysql_config'".
-
Rebuild and Install: Run "sudo python setup.py build" and then "sudo python setup.py install".
-
Test Installation: Verify by importing MySQLdb in Python: "python >>> import MySQLdb"
-
Additional Symlink for libmysqlclient.18.dylib Error: If encountered, execute: "sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib".
Common Error:
If the error "Module _mysql was already imported from..." appears, exit the build directory by "cd .." to resolve it.
The above is the detailed content of How Can I Successfully Install MySQLdb on Mac OS X?. For more information, please follow other related articles on the PHP Chinese website!