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 答案和谷歌结果,想不出还有什么可以尝试的.任何建议将不胜感激.
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