我的操作系统是win7
64bit,平时一直用的是python2.5.4的版本,因为今天需要用到python读取mysql数据库,不过网络上没有支持python2.5.4的64bit
mysql包版本。所以换了python2.6,反正只是临时解决方案,写完程序之后还会换回来的。然后在使用过程中遇到一些问题。
先列一下软件下载的地址
python2.6
64bit下载:MySQL-python-1.2.2.win-amd64-py2.6:先后安装完毕之后,先打开IDEL准备测试一下
import
MySQLdb
import MySQLdb
Traceback (most recent call
last):
File
"", line 1, in
import MySQLdb
File
"C:\Python26\Lib\site-packages\MySQLdb\__init__.py",
line 34, in
from sets import ImmutableSet
File "C:\Python26\Lib\sets.py", line 85, in
stacklevel=2)
File "C:\Python26\lib\warnings.py", line 29, in
_show_warning
file.write(formatwarning(message, category, filename,
lineno, line))
TypeError: idle_formatwarning_subproc() takes exactly 4
arguments (5 given) 居然连导入包都不能......
太扯淡了,第一时间搜索了一下,得到解决方案.
解决办法来源:
修改
\Python26\Lib\site-packages\MySQLdb\__init__.py
第34行
#注释这一条语句
from sets import
ImmutableSet
#添加以下语句.
ImmutableSet =
frozenset
在第四十行添加一条
保存完毕,OK,测试一下
#!/usr/bin/env
python
#coding=utf-8
import MySQLdb
conn
= MySQLdb.connect (host = "localhost",
user = "root",
passwd = "root",
db
= "test")
cursor = conn.cursor
()
cursor.execute ("SELECT VERSION()")
row =
cursor.fetchone ()
print "server version:",
row[0]
cursor.close ()
conn.close
()
运行结果,一切正常,开始工作了,等写完测试程序后再来研究这个bug究竟是怎么回事.
C:\Python26\lib\site-packages\MySQLdb\converters.py:37:
DeprecationWarning: the
sets module is deprecated
from sets import BaseSet, Set
server version:
5.0.67-community-nt
本文出自 “九黎部落” 博客,请务必保留此出处http://axiii.blog.51cto.com/396236/340455