我已经来了一段时间,并阅读了许多有关该主题的网站。怀疑我有垃圾造成了这个问题。但是哪里?
当我在python中导入MySQLdb时,这是错误:
>>> import MySQLdb /Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.pyc, but /Users/phoebebr/Downloads/MySQL-python-1.2.3c1 is being added to sys.path Traceback (most recent call last): File "<stdin>", line 1, in <module> File "MySQLdb/__init__.py", line 19, in <module> import _mysql File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module> File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__ ImportError: dlopen(/Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found. Did find: /Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture
我正在尝试64位,所以在这里检查:
file $(which python) /usr/bin/python: Mach-O universal binary with 3 architectures /usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/python (for architecture i386): Mach-O executable i386 /usr/bin/python (for architecture ppc7400): Mach-O executable ppc file $(which mysql) /usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
已将python的默认版本设置为2.6
python Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
尝试删除构建目录和python setup.py clean重命名为Python / 2.5 / site-packages,使其无法尝试提取它。
删除所有内容,并按照此处的说明进行操作: Mac OS 10.6.2上的Django + MySQL使用Macports安装Snow Leopard。
但是基本上还是会得到同样的错误
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py", line 19, in <module> import _mysql ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so, 2): no suitable image found. Did find: /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so: mach-o, but wrong architecture >>>
当口译员说的是:
您已经在/Library/Python/2.6/site-packages中安装了MySQL_python-1.2.3c1,但是您正在/ users / phoebebr / Downloads中向sys.path添加了另一个版本。当我尝试从第二个目录导入MySQLdb时,我发现_mysql.so来自另一种体系结构。
因此,看来您以错误的MySQLdb版本结束了。删除/Users/phoebebr/.python- eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg- tmp和/Users/phoebebr/Downloads/MySQL-python-1.2.3c1。再次测试以查看/ library中的版本是否有效。如果不是,请为MacOS下载二进制文件。最后,下载MySQL-python的源代码并进行编译。