python有没有自带mysqldb模块_Python的MySQLdb模块安装

在配置Django时,选择的是mysql数据库,要安装MySQLdb模块,不过安装过程中,遇到了很多errors,记录一下。

系统:ubuntu 11.10

mysql:直接apt-get安装的,version:5.1.62

到官方下载MySQL for Python

然后解压,打开README:

里面有安装过程:

$ tar xfz MySQL-python-1.2.1.tar.gz

$ cd MySQL-python-1.2.1

$ # edit site.cfg if necessary

$ python setup.py build

$ sudo python setup.py install # or su first

不过在python setup.py build时报错:

ImportError: No module named setuptools

ubuntu下安装:

sudo apt-get install python-setuptools

python-setuptools : Python Distutils Enhancements (setuptools compatibility)

然后再次python setup.py build,又报错:

EnvironmentError: mysql_config not found

因为mysql_config是属于MySQL开发用的文件,而使用apt-get安装的MySQL是没有这个文件的,于是在包安装器里面寻找

sudo apt-get install libmysqld-dev

libmysqld-dev : MySQL embedded database development files

再次运行python setup.py build,报错:

building ‘_mysql’ extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,’final’,0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX

In file included from _mysql.c:29:0:

pymemcompat.h:10:20: fatal error: Python.h: No such file or directory

解决方案,

sudo apt-get install python-dev

python-dev : header files and a static library for Python (default)

然后就按照README里的:

$ python setup.py build

$ sudo python setup.py install

测试:

>>>import MySQLdb

没有报错即可。

参考:

http://blog.csdn.net/guzicheng/article/details/5884106

http://be-evil.org/post-185.html

http://hi.baidu.com/hevensun/blog/item/3b6e313fe8515df154e7238f.html

http://stackoverflow.com/questions/1449130/how-to-install-mysqldb-package-importerror-no-module-named-setuptools

http://www.cnblogs.com/objdump/archive/2011/11/03/mysql_python_install_error.html

src:http://www.cnblogs.com/rollenholt/archive/2012/05/07/2487137.html

posted on

2016-01-10 21:44

飞奔的猪

阅读(200)

评论(0)

编辑

收藏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值