mysql-python安装问题(在Mac OS X Lion上)

mysql-python安装问题(在Mac OS X Lion上)

问题描述:

我成功安装了所有内容,或者我以为:

I installed everything successfully, or so I thought:

  • 适用于x86_64的MySQL 5.5.
  • Python 2.7,x86_64.
  • mysql-python 1.2.3,x86_64.

但是当我尝试:

import MySQLdb

我得到:

    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

我还能缺少什么?

我的系统当然也是64位版本,uname -a给出:

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

我认为我已经阅读了大多数SO答案和关于该主题的Google结果,想不出要尝试的其他方法.任何建议将不胜感激.

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.

借助@birryree的注释,我发现了问题所在.按照@birryree在他的回答中建议的步骤,我可能会更好,但我之前确实尝试过,并且行得通:

With the help of the comment from @birryree I found the problem. I would probably be better off following the procedure suggested by @birryree in his answer but I did try this before and it worked:

按照建议,我做了:

file /Users/aj/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-ix86_64.egg-tmp/_mysql.so

获取:[...]: Mach-O bundle i386 因此,错误的体系结构.从那里,我对mysql和python进行了相同的操作,只是为了确保: file $(which python)给出了:

To get: [...]: Mach-O bundle i386 So, wrong architecture. From there I did the same with mysql and python just to be sure: file $(which python) gave:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture i386):   Mach-O executable i386
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64

file $(which mysql):

/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64

因此,我卸载了mysql-python软件包:sudo pip uninstall mysql-python并再次安装了它.但是这样做时,我在安装此软件包时意识到了先前的错误.第一次输入:

So I uninstalled the mysql-python package: sudo pip uninstall mysql-python and installed it again. But doing this I realized my previous mistake while installing this package. First time I typed:

sudo ARCHFLAGS='-arch ix86_64' python setup.py build(然后安装")

架构名称错误,应为'-arch x86_64',不能为"i",因此它只是忽略了我的标志并安装了32位.

The architecture name was wrong, should be '-arch x86_64', no "i", so it just ignored my flag and installed the 32bit.

正确的命令以从源文件夹安装64位下载的mysql-python软件包:

The proper commands to install the downloaded mysql-python package for 64bit (from the source folder):

sudo ARCHFLAGS='-arch x86_64' python setup.py build
sudo ARCHFLAGS='-arch x86_64' python setup.py install