ubuntu python2.7安装mysql-python

 

Python连接mysql

 

>>> import MySQLdb
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import MySQLdb
ImportError: No module named MySQLdb
>>> 
 

 

 解决方法:

1. sudo easy_install mysql-python

若报错,提示找不到setuptools

需要先安装setuptools

2. sudo apt-get install  python-setuptools

继续执行 1 

若提示EnvironmentError: mysql_config not found(即找不到mysql_config)原因没有安装libmysqlclient

3. 在/etc/apt/sources.list 中加入 deb http://security.ubuntu.com/ubuntu maverick-security main     

4.  sudo apt-get install libmysqlclient-dev

 仍然失败,提示找不到Python.h

5. 在/etc/apt/sources.list 中加入 deb http://ubuntu.mirror.cambrium.nl/ubuntu/ maverick main

 6. 执行 sudo apt-get install python-dev

重新执行1 ,mysql-python安装成功

你可能感兴趣的:(mysql,python,ubuntu,mysql-python,mysql_config)