在Mac OS X上安装MySQLdb

时间:2022-09-19 00:29:15

I've spent several hours trying to install MySQLdb (the Python library) on Mac OS X Snow Leopard. I'm using these instructions from 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

4 个解决方案

#1


9  

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在Snow Leopard上使用Python 2.6,并且遇到了很多架构问题。最终为我解决的是确保我的Python和MySQL安装都使用像我的Snow Leopard那样的32位架构。

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...

祝你好运...

#2


52  

sudo pip install mysql-python worked for me in 10.8.1.

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

#3


4  

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

#4


1  

You can also force python to run in 32bit mode:

您还可以强制python以32位模式运行:

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

#1


9  

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在Snow Leopard上使用Python 2.6,并且遇到了很多架构问题。最终为我解决的是确保我的Python和MySQL安装都使用像我的Snow Leopard那样的32位架构。

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...

祝你好运...

#2


52  

sudo pip install mysql-python worked for me in 10.8.1.

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

#3


4  

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

#4


1  

You can also force python to run in 32bit mode:

您还可以强制python以32位模式运行:

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