我成功安装了所有内容,或者我以为:
但是当我尝试:
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它给出了:
uname -a
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在该主题上的结果,想不出要尝试的其他方法。任何建议,将不胜感激。
借助于@birryree的评论,我发现了问题。按照@birryree在他的回答中建议的步骤,我可能会更好,但我之前确实尝试过,并且有效:
按照建议,我做了:
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):
[...]: Mach-O bundle i386
file $(which python)
/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):
file $(which mysql)
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
因此,我卸载了mysql-python软件包:sudo pip uninstall mysql- python并再次安装了它。但是这样做时,我在安装此软件包时意识到了先前的错误。第一次输入:
sudo pip uninstall mysql- python
sudo ARCHFLAGS='-arch ix86_64' python setup.py build (然后是“安装”)
sudo ARCHFLAGS='-arch ix86_64' python setup.py build
架构名称错误,应为-arch x86_64,而不是“ i”,因此它只是忽略了我的标志并安装了32位。
正确的命令安装下载的mysql-python包的64位(从源文件夹):
sudo ARCHFLAGS='-arch x86_64' python setup.py build sudo ARCHFLAGS='-arch x86_64' python setup.py install