mac 装 mysql-python的坑

作为小白,折腾了很久,查了很多资料,才把这儿坑给填了

一般来说,安装mysql-python 驱动,只需要

pip install mysql-python

可是会报错。

mac 装 mysql-python的坑_第1张图片

 Using cached MySQL-python-1.2.5.zip    

Complete output from command python setup.py
egg_info:     sh: mysql_config: command not found    
Traceback (most recent call last):      
 File "", line 1, in       File "/private/var/folders/5r/z0n8d2bx1gng1bcbptynj6wr0000gn/T/pip-build-af7hi2/mysql-python/setup.py", line 17, in         metadata, options = get_config()       File "setup_posix.py", line 43, in get_config         libs = mysql_config("libs_r")       File "setup_posix.py", line 25, in mysql_config         raise EnvironmentError("%s not found" % (mysql_config.path,))     EnvironmentError: mysql_config not found          ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/5r/z0n8d2bx1gng1bcbptynj6wr0000gn/T/pip-build-af7hi2/mysql-python/

解决方法

1 官网现在 mysql-python

https://pypi.python.org/pypi/MySQL-python/1.2.5

2 解压,并在文本编辑软件中,修改解压文件夹中的site.cfg


mac 装 mysql-python的坑_第2张图片

3 找到如下的句子

# 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

修改后的格式为

# 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/mysql/bin/mysql_config


5 用terminal 进入 加压后的文件, 并运行 $ python setup.py install

$ python setup.py install

你可能感兴趣的:(mac 装 mysql-python的坑)