First off, I'm no pro at python. PHP is (currently) my area of expertise when it comes to scripting languages. That said, I'm intrigued by Django and wanted to try it out for a couple of small internal projects that have been sitting at the bottom of my todo list. I went to work building a development environment on my macbook pro and ran into the following error while trying to get MySQL-python working. This error occurred after installing MySQL-python and trying to load the library with the interpreter via the CLI. I've bolded the part I found interesting.
>>> import MySQLdb
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/MySQL_python-1.2.2-py2.4-macosx-10.3-fat.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/MySQL_python-1.2.2-py2.4-macosx-10.3-fat.egg/_mysql.pyc, but /Users/adam/Desktop/MySQL-python-1.2.2 is being added to sys.path
Traceback (most recent call last):
File "", line 1, in ?
File "MySQLdb/__init__.py", line 19, in ?
import _mysql
File "build/bdist.macosx-10.3-fat/egg/_mysql.py", line 7, in ?
File "build/bdist.macosx-10.3-fat/egg/_mysql.py", line 6, in __bootstrap__
ImportError: Failure linking new module: /Users/adam/.python-eggs/MySQL_python-1.2.2-py2.4-macosx-10.3-fat.egg-tmp/_mysql.so: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient_r.15.dylib
Referenced from: /Users/adam/.python-eggs/MySQL_python-1.2.2-py2.4-macosx-10.3-fat.egg-tmp/_mysql.so
Reason: image not found
>>>
I spent maybe 5 minutes searching Google but nobody had a simple answer that I liked. I didn't want to re-compile python or download somebody's pre-built libraries. I'm trying to test out Django with as little time and changes to my machine as possible.
Not being a python regular, I don't know what most of the error above means. But, I do know that the bolded file doesn't exist on my computer. Having a look, I found the file in a similar yet more reasonable area: /usr/local/mysql/lib/libmysqlclient_r.15.dylib
Here's the simple fix:
sudo mkdir /usr/local/mysql/lib/mysql/
sudo ln -s /usr/local/mysql/lib/libmysqlclient_r.15.dylib /usr/local/mysql/lib/mysql/
A quick python manage.py syncdb on my Django project proved success.
Comments
Anonymous (not verified)
Sat, 11/10/2007 - 20:26
Permalink
Had this exact problem, and
Had this exact problem, and your solution worked perfectly. Thanks!
Anonymous (not verified)
Fri, 11/30/2007 - 18:05
Permalink
worked perfectly
thanks so much
Anonymous (not verified)
Mon, 12/24/2007 - 17:07
Permalink
more extensible solution
rather than just link in a single file, add a link that "fixes" the problem of the extra directory level.
sudo ln -s . /usr/local/mysql/lib/mysql
now /usr/local/mysql/lib/mysql points to /usr/local/mysql/lib, and any file in that directory is visible.
adam
Tue, 12/25/2007 - 17:14
Permalink
Right, this is something I
Right, this is something I ended up doing when trying to get PHP to compile with mysql support on OS X 10.5. Thanks for mentioning it.
Anonymous (not verified)
Wed, 01/30/2008 - 11:30
Permalink
thanks
Thanks, worked like a charm when I linked the entire directory.
Anonymous (not verified)
Thu, 03/27/2008 - 18:42
Permalink
Wonderful!!
Thank you so much for this fix. Saved me HOURS.