Question

I simply want to install MySQL on my Mac (running Mac OS X 10.6.5 (Snow Leopard)) for use with Python.

So far I have:

  1. Downloaded and installed [mysql-5.5.8-osx10.6-x86_64.dmg]. (I have also accidentally downloaded and installed [mysql-5.1.54-osx10.6-x86_64.dmg])

  2. Downloaded and installed [mySQL-python-1.2.3]

  3. Added the following to my .bash_profile:

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

But when I run:import mySQLdb in terminal, I am met with the following message:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mySQLdb

How can I fix this problem?

UPDATE: Okay, so I tried the MacPorts install, but still it is not working. I got the following error messages...

Error: db46 requires the Java for Mac OS X development headers.
Error: Download the Java Developer Package from: https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719

Error: Target org.macports.configure returned: missing Java headers

Error: Failed to install db46
Log for db46 is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_db46/main.log

Error: The following dependencies were not installed: py26-distribute python26 db46 gdbm gettext expat libiconv gperf sqlite3

Error: Status 1 encountered during processing.

It doesn't mean much to me, though I'm guessing the second-to-last one explains why Python is not where it should be.

Was it helpful?

Solution

It is certainly possible to make it all work by yourself. But there are a lot of pieces and, especially on OS X 10.6 and its preference for running in 64-bit, it can be difficult to get everything right. We could debug each step along the way; to do that you are going to need to supply more information. Or you could do yourself a favor and install everything from a 3rd-party package manager, like MacPorts, Fink, or Homebrew. That makes even more sense if you are going to be installing more packages. I happen to prefer MacPorts. If you haven't already installed its base files, follow the instructions here. If you have installed it already, then do this to make sure the list of ports is up-to-date:

$ sudo port selfupdate

Then you can install everything you need with one command:

$ sudo port install py26-mysql

When it's done:

$ /opt/local/bin/python2.6 -c "import MySQLdb; print(MySQLdb.version_info)"
(1, 2, 3, 'final', 0)

Update: based on the additional information you supplied, it appears that a recent change to the Java distribution on OS X 10.6 causes one of the dependent libraries, db46, to fail. The easiest way around that should be to add a command to select its non-Java variant:

$ sudo port clean db46
$ sudo port install db46 +no_java
$ sudo port install py26-mysql

OTHER TIPS

This

import MySQLdb

works for me (case is different). Otherwise, make sure the egg is properly installed (e.g. in /Library/Python/2.6/site-packages/MySQL_python)

I have had great luck using MAMP instead of installing MySQL and Python directly onto my Mac with Snow Leopard. I have heard horror stories of customized MySQL and Python installations breaking when you run certain updates from Apple. That, and the ability to easily disable Apache, MySQL, PHP and Python from running in the background while not needed is why I went with MAMP.

Number 8 on this webpage walks you through how to get Python setup: http://www.sitepen.com/blog/2008/05/16/supercharge-mamp/

More information on MAMP can be found here: http://www.mamp.info/en/mamp/index.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top