1、在Linux中系统默认使用python2.7,所以需要安装python-pip
sudo apt install python-pip
2、使用pip安装mysql-python
sudo pip install mysql-python
注意:此刻会抛出一个错误,我安装过很多机器都出现了这个错误。
Complete output from command python setup.py egg_info:
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-0PWaDX/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-0PWaDX/mysql-python/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-0PWaDX/mysql-python/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
mysql_config找不到,因为这个文件不在mysql-python里面,在libmysqlclient-dev里面,所以需要安装libmysqlclient-dev。
3,再次安装mysql-python
sudo pip install mysql-python
到这里就安装完成。安装过很多都是可以的了。