python mysql python.h_MySQLdb: Python.h: No such file or directory

Extract it and run:

python setup.py build

sudo python setup.py install

If 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 1

Installing the python-dev package on Debian is done with apt-get or

synaptic:

apt-get install python-dev

Installing the library should now work:

python setup.py build

python setup.py install

Next 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.rowcount

Don’t forget to close the cursor and connection, and if you’re

inserting data commit before closing, because autocommit is

disabled by default:

cursor.close ()

conn.commit ()

conn.close ()

For more information about MySQLdb see

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值