模塊介紹:
xlrd 0.7.5 下載地址:http://pypi.python.org/pypi/xlrd 文檔地址:https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html
xlwt 0.7.3 下載地址:http://pypi.python.org/pypi/xlwt 文檔地址:https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/doc/xlwt.html
模塊安裝:
分別將tar.gz文件包解壓,在cmd命令行窗口,進入到xlrd或xlwt,運行python setup.py install。前提是系統變量Path中已添加C:\Python26。
現進入Python解釋器,import xlwt,正常無報錯。import xlrd,卻
>>> import xlrd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\Lib\site-packages\xlrd\__init__.py", line 4, in <module>
__VERSION__ = open(path.join(path.dirname(__file__), 'version.txt')).read().
strip()
IOError: [Errno 2] No such file or directory: 'C:\\Python26\\lib\\site-packages\
\xlrd\\version.txt'
很明顯,是文件version.txt不存在所致。打開"C:\Python26\Lib\site-packages\xlrd\__init__.py"文件,將第四行的__VERSION__ = open(path.join(path.dirname(__file__), 'version.txt')).read().strip()注釋掉,新增一行為__VERSION__ = '0.7.4',現在import xlrd,就正常無報錯。
源代碼中的第四行是讀取版本號,而該模塊版本號在第16行進行了描述,參照C:\Python26\Lib\site-packages\xlwt\__init__.py文件,即可解決此問題。