我的操作系統是win7 64bit,平時一直用的是python2.5.4的版本,因爲今天需要用到python讀取mysql數據庫,不過網絡上沒有支持python2.5.4的64bit mysql包版本。所以換了python2.6,反正只是臨時解決方案,寫完程序之後還會換回來的。然後在使用過程中遇到一些問題。
先列一下軟件下載的地址
python2.6 64bit下載:http://www.python.org/ftp/python/2.6/python-2.6.amd64.msi
MySQL-python-1.2.2.win-amd64-py2.6:http://www.codegood.com/download/3/
先後安裝完畢之後,先打開IDEL準備測試一下
import MySQLdb
import MySQLdb
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import MySQLdb
File "C:\Python26\Lib\site-packages\MySQLdb\__init__.py", line 34, in <module>
from sets import ImmutableSet
File "C:\Python26\Lib\sets.py", line 85, in <module>
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)
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import MySQLdb
File "C:\Python26\Lib\site-packages\MySQLdb\__init__.py", line 34, in <module>
from sets import ImmutableSet
File "C:\Python26\Lib\sets.py", line 85, in <module>
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)
居然連導入包都不能...... 太扯淡了,第一時間搜索了一下,得到解決方案.
解決辦法來源:http://flo.nigsch.com/?p=62
修改\Python26\Lib\site-packages\MySQLdb\__init__.py
第34行
#註釋這一條語句 from sets import ImmutableSet
#添加以下語句.
ImmutableSet = frozenset
#註釋這一條語句 from sets import ImmutableSet
#添加以下語句.
ImmutableSet = frozenset
在第四十行添加一條
BaseSet = set
保存完畢,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 ()
#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
sets module is deprecated
from sets import BaseSet, Set
server version: 5.0.67-community-nt