$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.6
BuildVersion: 16G29
$ python -V
Python 2.7.14
某個(gè)項(xiàng)目開(kāi)發(fā)要用到 MySQL-Python 庫(kù)堰乔,然而 pip install 安裝失敗磺浙,goole 后找到解決方法愿卒,總結(jié)下灵莲。
出錯(cuò):
Collecting MySQL-Python
Using cached https://pypi.doubanio.com/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/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 "<string>", line 1, in <module>
File "/private/var/folders/bb/skpfxrzj1jv863wm99wcb_z00000gp/T/pip-build-IiQWYZ/MySQL-Python/setup.py", line 17, in <module>
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/bb/skpfxrzj1jv863wm99wcb_z00000gp/T/pip-build-IiQWYZ/MySQL-Python/
mysql_config
在 Mac 下是由 mysql-connector-c
提供的
$ brew install mysql
$ brew install mysql-connector-c
Collecting MySQL-Python
Using cached https://pypi.doubanio.com/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/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 "<string>", line 1, in <module>
File "/private/var/folders/bb/skpfxrzj1jv863wm99wcb_z00000gp/T/pip-build-IiQWYZ/MySQL-Python/setup.py", line 17, in <module>
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/bb/skpfxrzj1jv863wm99wcb_z00000gp/T/pip-build-IiQWYZ/MySQL-Python/
但是安裝完 mysql 相關(guān)依賴(lài)后依舊報(bào)錯(cuò)蜈敢,后來(lái)搜到要修改 mysql_config
配置解決
$ which mysql_config
/usr/local/bin/mysql_config
$ vim /usr/local/bin/mysql_config
libs="$libs -l "
修改為
libs="$libs -lmysqlclient -lssl -lcrypto"
ref: https://github.com/PyMySQL/mysqlclient-python/issues/169
此時(shí)可成功安裝
$ pip install MySQL-Python
Collecting MySQL-Python
Using cached https://pypi.doubanio.com/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Building wheels for collected packages: MySQL-Python
Building wheel for MySQL-Python failed: [Errno 13] Permission denied: '/Users/evil/Library/Caches/pip/wheels/5a'
Failed to build MySQL-Python
Installing collected packages: MySQL-Python
Running setup.py install for MySQL-Python ... done
Successfully installed MySQL-Python-1.2.5