2011-04-03 170 views
9

我花了几个小时试图在Mac OS X Snow Leopard上安装MySQLdb(Python库)。我正在使用SO的these instructions。我不断收到一个错误,所以我尝试过使用MacPorts(作为对该问题的答案之一的建议),但我仍然得到相同的错误。任何人都可以帮忙吗?在Mac OS X上安装MySQLdb

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 
+0

试过ActivePython的? http://code.activestate.com/pypm/mysql-python/ – 2011-04-04 17:51:25

+0

[如何在Mac OS X上安装MySQLdb(Python数据访问库到MySQL)的可能的重复?](http://stackoverflow.com/questions/ 1448429/how-to-install-mysqldb-python-data-access-library -to-mysql-on-mac-os -x) – Mark 2011-09-03 10:51:36

回答

9

Ack。我感到你的痛苦。我花了很长时间也尝试使用Macbook Air在Snow Leopard上使用Python 2.6来处理MySQL,并且存在很多体系结构问题。最终为我解决的是,确保我的Python和MySQL安装都使用了像我的雪豹一样的32位体系结构。

我写了一篇关于我的解决方案在这里,所以也许这将帮助:

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

好运...

+0

@ Spike-链接被再次破坏。虽然提供链接没有问题,但这说明了SO政策为什么要在SO上提供完整的问题答案,并提供了供参考或更详细的链接。 – kmarsh 2014-03-07 15:05:17

4

尝试这种在.bashrc或者.bash_profile中

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 
+0

在做一个'pip安装之前运行这些mysql-python'结束了对我来说很好的工作。在我的具体情况下,我需要64位并交换了VERSIONER_PYTHON_PREFER_XX_BIT标志的值。 – scwagner 2012-04-02 03:34:56

52

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

1

您还可以强制蟒蛇在32位模式运行:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes