0

I'm needing to connect to a MySQL database that is on my local machine via a Python script. Here's my setup:

  • Installed (and have been using for developing web apps for several months) MySQL 5.6.22 (downloaded .dmg from here)
  • Running the pre-installed python (2.7) that came with Yosemite
  • Downloaded: MySQL-python-1.2.4b4.tar.gz and installed via terminal by running python setup.py install in the unzipped folder

This is the output I got at the end of the installation:

Installed /Library/Python/2.7/site-packages/distribute-0.6.28-py2.7.egg
Processing dependencies for distribute==0.6.28`
Finished processing dependencies for distribute==0.6.28
Processing MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg
creating /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg
Extracting MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg to /Library/Python/2.7/site-packages
Adding MySQL-python 1.2.4b4 to easy-install.pth file

Installed /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg
Processing dependencies for MySQL-python==1.2.4b4
Finished processing dependencies for MySQL-python==1.2.4b4

But when trying to connect, my py script gives me this error:

ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg/_mysql.so
Reason: image not found
('result', 256)

When I do

$ python
>>> import MySQLdb

I get the same error.

Any ideas on how I might get this sorted out?

Circle B
  • 1,616
  • 3
  • 26
  • 45
  • Check this http://stackoverflow.com/questions/17599830/installing-mysql-python-on-mac – thavan Mar 20 '15 at 18:16
  • @thavan I've got Developer tools installed and pip refuses to install, it gives me this error everytime: `Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. (read timeout=15)",)': /simple/pip/` – Circle B Mar 21 '15 at 02:13

1 Answers1

0

First, you should make sure you have libmysqlclient.18.dylib. On my mac, it's path is: /opt/local/lib/mysql56/mysql/libmysqlclient.18.dylib. If you don't have, you may need to get it by installing mysql5-devel.

If you have the dynamic library, the reason is that _mysql.so's information is wrong. You can use otool command to check it.

otool -L /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg/_mysql.so

It will show that the path this command tells you is not the correct path of the dynamic library. You can use the following command to fix it.

sudo install_name_tool -change libmysqlclient.18.dylib {this is the correct path for mysql dynamic library} /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.10-intel.egg/_mysql.so