Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

mysql-python installation problems (on mac os x lion)

I installed everything successfully, or so I thought:

  • MySQL 5.5 for x86_64.
  • Python 2.7, x86_64.
  • mysql-python 1.2.3, x86_64.

But when I try:

import MySQLdb

I get:

    ImportError: 
dlopen(/Users/aj/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-ix86_64.egg-tmp/_mysql.so, 2): 
no suitable image found.  
Did find:   
/Users/aj/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-ix86_64.egg-tmp/_mysql.so: mach-o, 
but wrong architecture

What else can I be missing?

My system is of course 64bit version as well, uname -a gives:

Darwin ajmacbook.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64

I think I have read most SO answers and Google results on the subject, can't think of anything else to try. Any suggestion would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think there might be slight quirks with doing this on Mac 64-bit (and if you google this problem shows up a lot too).

I've run into it, and there are a couple things you can do:

Override the environment

You can change the DYLD_LIBRARY_PATH environment variable, which tells the linker where to look for dynamic libraries (.so files and such). You said you also downloaded the 64-bit version of MySQL, so where ever it's installed, change the path you see here:

In a shell:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

And then run python and see if you can import MySQLdb.

If that works, you can make this permanent by altering your shell profile (.bash_profile, most likely).

Use homebrew

I don't really like mucking around with making sure MySQL and Python and all that are correct architectures and installing them separately. I run homebrew, which is a sort of package manager for Mac. If you install that, you can pretty easily take care of this issue:

  • brew install python
  • brew install mysql
  • /usr/local/share/python/easy_install mysql-python

Do note that homebrew installs into /usr/local, so you should add /usr/local/bin to your PATH, ahead of /usr/bin and /bin, otherwise you'll get really confused why python is different.

You can add /usr/local/share/python to your PATH as well, to make it permanent.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...