報錯信息:
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 "<string>", line 1, in <module>
?????? File "/tmp/pip-build-Lil8nB/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 /tmp/pip-build-Lil8nB/MySQL-python/
解決方法:(注:這里只是我遇到的問題,摸索到的解決方法,并不表示可以解決所有遇到此類的錯誤!)
[root@sishen ~]#python -m pip install --upgrade --force pip
[root@sishen ~]#pip install setuptools==33.1.1
[root@sishen ~]#yum install -y mysql-dev python-dev libmysqlclient-dev??? (紅色部分,依據個人情況安裝)
[root@sishen ~]#pip install MySQL-python
測試
[root@sishen ~]# python
Python 2.7.14 (default, Sep 20 2017, 20:34:26)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
這就表示已經成功安裝MySQL-python。