mac安装MySQLdb:IndexError: string index out of range
使用mac安装MySQLdb的时候出现string index out of range
大概的错误是这样的:
然后尝试手动安装,我下载了包后,依然出现这个错误。
于是百度了下:
https://www.jianshu.com/p/da9dd5dd4bd2
这个匹配度是最高的,但是这个兄弟居然半路放弃了(没有转载哈)....
后来我就google了下,
原贴地址:https://stackoverflow.com/questions/51123044/pip-install-mysql-python
最后得出结论:
(前提:基于brew安装,如果没有安装,请自行百度安装,就一句话。)
1.首先安装mysql-connector-c
brew install mysql-connector-c
2.然后修改mysql_config 的内容
vim /usr/local/bin/mysql_config
修改内容:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
替换成:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
3.设置环境变量
brew info openssl
it would tell what’s needed
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
4.然后再执行安装
pip install MySQL-python
大功告成