1

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.

3 Answers 3

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the info. Had already downloaded macports but wasn't immediately obvious how to use it and it was getting late so I decided against using it. Have followed your instructions, and aside from one error reported one completion of the "sudo port install..." went okay. The last command however is failing because python 2.6 isn't in /opt/local/bin/. Should it have been put there by the previous commands? Or do I just need to find where it is and sub in the correct path.
MacPorts installs everything by default under /opt/local/ so it should be there. What was the error reported by sudo port install? What does an ls -l /opt/local/bin show?
Sorry, really struggling to post the error messages I got during install. These comment boxes aren't big enough for all the text and don't format appropriately. I'm reluctant to use the 'Post an answer' option because it isn't an answer! I have a screen shot of the terminal window at the end of the install - Is there any way I can post that here?
Have now implemented your three sudo commands to install the non-java variant, and all seems to be working okay. No error messages received, and 'import MySQLdb' works fine when entered at interactive session prompt. Many thanks for your time; would never have got that sorted otherwise.
0

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)

2 Comments

Tried capitalising M but no joy. What is the egg?
Okay, searched for egg on net and realised it was one of the files I had already downloaded. It is now in Library/Python/2.6/site-packages/MySQL-python-1.2.3 but still getting same error message (also added this to my PATH in .bash_profile just in case it wasn't included by default.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.