1、下载mysql-python
官网地址:http://sourceforge.net/projects/mysql-python/
2、安装mysql-python
复制代码 代码如下:
mysql_config: /usr/bin/mysql_config /usr/share/man/man1/mysql_config.1.gz
threadsafe = False
mysql_config = /usr/bin/mysql_config
mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
注意:
1.编译mysql-python需要mysql头文件。
2.安装mysql-python需要setuptools工具。
3、测试
复制代码 代码如下:
import MySQLdb
如果没有错误提示或者以下错误提示,那么表示安装成功。
错误提示:
复制代码 代码如下:
/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.pyc, but /root/MySQL-python-1.2.3 is being added to sys.path
报错原因:
执行python setup.py install,MySQLdb模块会被拷贝python的site-packages目录。如果在执行python的目录中存在相同的模块,就可能重复导入模块。
解决办法:
换个目录执行python即可。
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8