今日,在安装Pylons时,前面的安装都非常的顺利,但是在安装MySQLdb工具时,在安装的时候就出现了一大陀错误,
在网上搜寻一番,和结合自己的实际情况,发现少安装了几个只要的软件包:
- mysql.c:2810: error: expected declaration specifiers before ‘init_mysql’
- _mysql.c:2888: error: expected ‘{’ at end of input
- error: <span style="color: #0000ff;">command 'gcc' failed with exit status 1</span>
apt-get install python-dev apt-get install libmysqlclient-dev 如此,安装就顺利完成了
Extract it and run:
python setup.py build sudo python setup.py installIf you get this error you need to install python-dev package:
In file included from _mysql.c:29: pymemcompat.h:10:20: error: Python.h: No such file or directory _mysql.c:30:26: error: structmember.h: No such file or directory In file included from /usr/include/mysql/mysql.h:44, from _mysql.c:40: . . . _mysql.c:2808: warning: return type defaults to 'int' _mysql.c: In function 'DL_EXPORT': _mysql.c:2808: error: expected declaration specifiers before 'init_mysql' _mysql.c:2886: error: expected '{' at end of input error: command 'gcc' failed with exit status 1Installing the python-dev package on Debian is done with apt-get or synaptic:
apt-get install python-devInstalling the library should now work:
python setup.py build python setup.py installNext test the library in the python console:
import MySQLdb # Note that this example uses UTF-8 encoding conn = MySQLdb.connect(host='localhost', user='...', passwd='...', db='...', charset = "utf8", use_unicode = True) cursor = conn.cursor() cursor.execute ("SELECT * FROM cities") rows = cursor.fetchall () for row in rows: print "%s, %s" % (row[0], row[1].encode('utf-8')) print "Number of rows returned: %d" % cursor.rowcountDon’t forget to close the cursor and connection, and if you’re inserting data commit before closing, because autocommit is disabled by default: