macos 在 Mac OS X 上安装 MySQLdb
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5531958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing MySQLdb on Mac OS X
提问by Joe Mornin
I've spent several hours trying to install MySQLdb (the Python library) on Mac OS X Snow Leopard. I'm using these instructionsfrom SO. I keep getting an error, so I've tried using MacPorts (as one of the answers to that question advises), but I continue to get the same error. Can anybody help?
我花了几个小时试图在 Mac OS X Snow Leopard 上安装 MySQLdb(Python 库)。我正在使用来自 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
采纳答案by Spike
Ack. I feel your pain. I spent a really long time also trying to get MySQL working with Python 2.6 on Snow Leopard using a Macbook Air and had lots of architecture problems. What ended up solving it for me, was making sure both my Python and MySQL installations were using a 32 bit architecture like my Snow Leopard was.
确认。我感觉到你的痛苦。我还花了很长时间试图让 MySQL 在雪豹上使用 Macbook Air 与 Python 2.6 一起工作,但遇到了很多架构问题。最终为我解决的问题是确保我的 Python 和 MySQL 安装都使用 32 位架构,就像我的 Snow Leopard 一样。
I wrote about my solution here, so maybe that'll help:
我在这里写了我的解决方案,所以也许这会有所帮助:
http://www.markliu.me/2010/jun/09/mysql-and-python-on-32-bit-snow-leopard/
http://www.markliu.me/2010/jun/09/mysql-and-python-on-32-bit-snow-leopard/
Good luck...
祝你好运...
回答by aaronsw
sudo pip install mysql-python
worked for me in 10.8.1.
sudo pip install mysql-python
在 10.8.1 对我来说有效。
回答by Peter Rosemann
try this in .bashrc or .bash_profile
在 .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
回答by Adriaan
You can also force python to run in 32bit mode:
你也可以强制python在32位模式下运行:
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes