一、安裝xlrd和xlwt功能模塊步驟
1.使用python -V查看python的版本號,並查看python安裝環境,是否安裝成功;



2.可以通過官網(python官網:https://pypi.python.org/pypi)或者其他手段獲取到功能模塊的安裝程序包;
3.將程序包解壓,並放在python->Lib文件下


4.在cmd命令窗口中,進入E:\Python\Python36\Lib目錄下,分別進入xlrd和xlwt的目錄下,執行python setup.py install命令;

5.在python工具中,執行import xlwt3和import xlrd,運行結果沒有報錯,則證明安裝成功;


二、
在使用xlwt時,報錯的解決方法
1.導入xlwt3報錯:ValueError: cannot use LOCALE flag with a str pattern
詳細錯誤信息:
Traceback (most recent call last):
File "F:/1/1", line 1, in <module>
import xlwt3
File "E:\Python\Python36\lib\site-packages\xlwt3\__init__.py", line 3, in <module>
from .workbook import Workbook
File "E:\Python\Python36\lib\site-packages\xlwt3\workbook.py", line 5, in <module>
from .worksheet import Worksheet
File "E:\Python\Python36\lib\site-packages\xlwt3\worksheet.py", line 7, in <module>
from .row import Row
File "E:\Python\Python36\lib\site-packages\xlwt3\row.py", line 8, in <module>
from . import formula
File "E:\Python\Python36\lib\site-packages\xlwt3\formula.py", line 1, in <module>
from .excel import formulaparser, formulalexer
File "E:\Python\Python36\lib\site-packages\xlwt3\excel\formulalexer.py", line 52, in <module>
VERBOSE+LOCALE+IGNORECASE)
File "E:\Python\Python36\lib\re.py", line 233, in compile
return _compile(pattern, flags)
File "E:\Python\Python36\lib\re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "E:\Python\Python36\lib\sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "E:\Python\Python36\lib\sre_parse.py", line 866, in parse
p.pattern.flags = fix_flags(str, p.pattern.flags)
File "E:\Python\Python36\lib\sre_parse.py", line 833, in fix_flags
raise ValueError("cannot use LOCALE flag with a str pattern")
ValueError: cannot use LOCALE flag with a str pattern
解決方法:
進入E:\Python\Python36\Lib\sre_parse.py文件下,修改該代碼:
if flags & SRE_FLAG_LOCALE:
pass #stone20170712 raise ValueError("cannot use LOCALE flag with a str pattern")
pass #stone20170712 raise ValueError("cannot use LOCALE flag with a str pattern")
執行import xlwt3,結果OK
2.導入xlwt3報錯:ValueError: '__init__' in __slots__ conflicts with class variable
詳細錯誤信息:
Traceback (most recent call last):
File "F:/1/1", line 1, in <module>
import xlwt3
File "E:\Python\Python36\lib\site-packages\xlwt3\__init__.py", line 3, in <module>
from .workbook import Workbook
File "E:\Python\Python36\lib\site-packages\xlwt3\workbook.py", line 5, in <module>
from .worksheet import Worksheet
File "E:\Python\Python36\lib\site-packages\xlwt3\worksheet.py", line 7, in <module>
from .row import Row
File "E:\Python\Python36\lib\site-packages\xlwt3\row.py", line 8, in <module>
from . import formula
File "E:\Python\Python36\lib\site-packages\xlwt3\formula.py", line 6, in <module>
class Formula(object):
ValueError: '__init__' in __slots__ conflicts with class variable
解決方法:
進入E:\Python\Python36\Lib\site-packages\xlwt3\formula.py文件下,將其中
__slots__ = [ "__init__","__s", "__parser", "__sheet_refs", "__xcall_refs"]
修改為:
__slots__ = [ "__s", "__parser", "__sheet_refs", "__xcall_refs"]
執行import xlwt3,結果OK