码迷,mamicode.com
首页 > 数据库 > 详细

Mac MySQLdb模块安装,可算解决了

时间:2016-05-17 00:28:56      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:

Python 2.7.3。

MySQL-python包中,因此无论下载还是在pip中search,都应该是搜寻MySQL-python。

 

 下载MySQLdb

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

 

$ easy_install MySQL-python --upgrade

 解决mysql_config not found错误

  因此下载安装时的解决办法为:在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的错误。

修改OS X环境变量:打开终端,在终端中使用vim打开“~/.bash_profile”,如果没有安装vim,那就显示隐藏文件用文本编辑器打开,具体操作这里就不复述了。在.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

  其中 VERSIONER_PYTHON_PREFER_64_BIT和VERSIONER_PYTHON_PREFER_64_BIT根据自己安装的MySQL进行选择。

 

$ sudo ln -s /usr/local/mysql/bin/* /usr/bin

 解决 Reason: image not found 错误

  安装完MySQL-python包后,让我们import MySQLdb,此时出现一个错误,错误最后一行写着 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:  clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

经网上查证:http://www.tuicool.com/articles/zI7Vzu貌似是mac os的Xcode从5.1起给编译器规定对于未知参数传入视为error我们需要使用ARCHFLAGS将该error降级为warning因此最后的安装命令应该如下:

 

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py build


参考

http://www.cnblogs.com/macro-cheng/archive/2011/10/25/mysql-001.html

Mac MySQLdb模块安装,可算解决了

标签:

原文地址:http://www.cnblogs.com/wuzhi-seo/p/5500039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!