使用mac安裝MySQLdb的時候出現string index out of rangepython
大概的錯誤是這樣的:mysql
而後嘗試手動安裝,我下載了包後,依然出現這個錯誤。sql
因而百度了下:vim
https://www.jianshu.com/p/da9dd5dd4bd2this
這個匹配度是最高的,可是這個兄弟竟然半路放棄了(沒有轉載哈)....google
後來我就google了下,spa
原貼地址:https://stackoverflow.com/questions/51123044/pip-install-mysql-pythonblog
最後得出結論:ip
(前提:基於brew安裝,若是沒有安裝,請自行百度安裝,就一句話。)ssl
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
大功告成