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

大功告成

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM