Mac系统Python安装MySQLdb的巨坑(已踩)

下载MySQLdb

在SourceForge可以下载MySQL-python-1.2.4b4.tar,下载后解压,然后在终端Terminal中执行以下命令:
 
new-host-3:~ iFantastic$ cd /Users/iFantastic/Downloads/MySQL-python-1.2.4b4
new-host-3:MySQL-python-1.2.4b4 iFantastic$ python setup.py install

使用pip安装MySQLdb

在终端中执行:
 
new-host-3:~ iFantastic$ pip install MySQL-python

无论是在线安装还是下载安装,此时你可能会遇到第一个错误提示:
 
EnvironmentError: mysql_config not found

建议使用pip安装,因为我从sourceforge下载的版本居然不如pip中的新。如果想要升级mysql-python版本,可以使用以下命令:
 
$ easy_install MySQL-python --upgrade

  [注意]如果你没有按照下文解决安装中的错误提示,那么升级也会因为同样的错误原因而失败。

解决mysql_config not found错误

在默认方式安装Mac版MySql时,会在/usr/local/mysql/bin目录下生成mysql_config文件。
因此下载安装时的解决办法为:在MySQL-python的安装包中找到site.cfg文件,打开它,找到以下内容:
  
# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
# mysql_config = /usr/local/bin/mysql_config

将最后一句句首井号去掉,并修改为:
 
mysql_config = /usr/local/mysql/bin/mysql_config

然后执行:
  
$ python setup.py install

一般说来,此时安装可以完成,但仍有问题,下文会继续阐述。
  
使用pip安装时没有办法修改site.cfg文件,因此可以通过修改OS X的系统环境变量来解决找不到mysql_config的错误。

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

其中VERSIONER_PYTHON_PREFER_64_BITVERSIONER_PYTHON_PREFER_64_BIT根据自己安装的MySQL进行选择。
另外再提供一个pip安装时找不到mysql_config的解决方法(我没有验证),在终端中输入以下命令:
  
$ sudo ln -s /usr/local/mysql/bin/* /usr/bin

好了,到这里,MySQL-python包应该基本顺利安装。
  

解决 Reason: image not found 错误
Reason: image not found。

解决方法是在终端执行:

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

错误:

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

再用pip下载一遍,此时如果还有报错,可加上–user。
例如:

pip install MySQL-python --user
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值