在Mac OS X上安装MySQLdb

2024-05-06 15:22:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我花了几个小时试图在Mac OS X雪豹上安装MySQLdb(Python库)。我用的是these instructions来自SO。我不断地得到一个错误,所以我尝试使用MacPorts(作为这个问题的答案之一),但我仍然得到同样的错误。有人能帮忙吗?

import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
  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/josephmornin/.python-egg-cache/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found.  
  Did find:
    /Users/josephmornin/.python-egg-cache/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture

Tags: inpybuildegg错误linemysqlusers
3条回答

在.bashrc或.bash_配置文件中尝试此操作

PATH="/usr/local/mysql/bin:${PATH}"
export PATH
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export VERSIONER_PYTHON_PREFER_64_BIT=no
export VERSIONER_PYTHON_PREFER_32_BIT=yes

确认。我感觉到你的痛苦。我花了很长时间也试图让MySQL使用Macbook Air在雪豹上使用Python 2.6,并且有很多架构问题。最终为我解决这个问题的是,确保我的Python和MySQL安装都使用32位架构,就像我的雪豹一样。

我在这里写了我的解决方案,也许这会有帮助:

http://www.markliu.me/2010/jun/09/mysql-and-python-on-32-bit-snow-leopard/

祝你好运。。。

sudo pip install mysql-python在10.8.1中为我工作。

相关问题 更多 >