在Mac上安装MySQLdb

时间:2012-10-27 09:14:02

标签: python mysql

我有Python 32位,我安装了MySQL社区服务器32位,我正在尝试为Python安装MySQLdb。 我跑

  

easy_install mysql-python

我有这个错误

> easy_install mysql-python
Searching for mysql-python
Reading http://pypi.python.org/simple/mysql-python/
Reading http://sourceforge.net/projects/mysql-python/
Reading http://sourceforge.net/projects/mysql-python
Best match: MySQL-python 1.2.4b5
Downloading http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.4b5.zip#md5=4f645ed23ea0f8848be77f25ffe94ade
Processing MySQL-python-1.2.4b5.zip
Running MySQL-python-1.2.4b5/setup.py -q bdist_egg --dist-dir /var/folders/ke/ke8HKCuzGB4LMCJ1eIAGqk+++TI/-Tmp-/easy_install-W_yT0e/MySQL-python-1.2.4b5/egg-dist-tmp-GjLaFB
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Extracting in /var/folders/ke/ke8HKCuzGB4LMCJ1eIAGqk+++TI/-Tmp-/easy_install-W_yT0e/MySQL-python-1.2.4b5/temp/tmpOVVY_R
Now working in /var/folders/ke/ke8HKCuzGB4LMCJ1eIAGqk+++TI/-Tmp-/easy_install-W_yT0e/MySQL-python-1.2.4b5/temp/tmpOVVY_R/distribute-0.6.28
Building a Distribute egg in /private/var/folders/ke/ke8HKCuzGB4LMCJ1eIAGqk+++TI/-Tmp-/easy_install-W_yT0e/MySQL-python-1.2.4b5
/private/var/folders/ke/ke8HKCuzGB4LMCJ1eIAGqk+++TI/-Tmp-/easy_install-W_yT0e/MySQL-python-1.2.4b5/distribute-0.6.28-py2.6.egg
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1

为什么无法找到gcc-4.0的任何想法?我安装了Xcode和gcc 4.2.1。

2 个答案:

答案 0 :(得分:1)

如果您使用的是Mountain Lion,您的问题似乎与未安装xcode命令行工具有关,如果您先从xcode安装它们,那么这应该可行

答案 1 :(得分:0)

如何:pip install mysql-python python 2.7 为了>>>import MySQLdb

我遵循了所有这些步骤并且我正在努力

对于brew,如果由于权限不允许您更新。

chgrp -R admin /usr/local
chmod -R g+w /usr/local
chgrp -R admin /Library/Caches/Homebrew
chmod -R g+w /Library/Caches/Homebrew

brew update
brew doctor  ## <--i did not use that
brew upgrade

ALSO I IGNORED THE Xcode update error

brew install mysql

pip install mysql-python

当我尝试导入MySQLdb时,它给我一些错误,所以我按照下面的链接提供的建议。

sudo ln -s /Users/$USERNAME/anaconda/lib/libssl.1.0.0.dylib /usr/lib/libssl.1.0.0.dylib
sudo ln -s /Users/$USERNAME/anaconda/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.1.0.0.dylib

我使用的链接

lib... issues

home bre update permission issue

install mysql with brew