模块的安装
1 、官网下载https://pypi.python.org/pypi/MySQL-python/1.2.5
2、解压zip文件,命令行进入该文件夹
$ cd /Users/enniu/Downloads/MySQL-python-1.2.5
3 、在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
4 、将最后一句句首井号去掉,并修改为:
mysql_config = /usr/local/mysql/bin/mysql_config
5、安装
$ python setup.py install #因为已使用绝对路径,故直接安装,不需要再加路径
或者直接命令行pip安装
$ pip install mysql-python
在sublime中无法import第三方模块的解决方案
1、sublime-preference-brower-python-python.sublime.build-添加环境变量
$ echo $PATH #PATH的作用是为了找到python
2、终端help(MySQLdb) #可以查看MySQLdb包的安装位置
结果如下:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]File "(...?)", line ([0-9]*)",
"selector": "source.python",
"path":"/Users/enniu/anaconda/bin:/python/anaconda/anaconda/bin:/python/anaconda/bin:/Users/enniu/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin",
"env": {"PYTHONPATH":"/Users/enniu/anaconda/lib/python2.7/site-packages"}
}