Python [ site-Package ] [ xlwt ] [ ValueError: cannot use LOCALE flag with a str pattern ]

  • 问题情境
    win7 + python3.7 + 读写execl时报错:

  • Log
    Traceback (most recent call last):
    File “parse-excel.py”, line 4, in
    import xlwt,xlrd,sys
    File “C:\Python37\lib\site-packages\xlwt_init_.py”, line 4, in
    from .Worksheet import Worksheet
    File “C:\Python37\lib\site-packages\xlwt\Worksheet.py”, line 38, in
    from .Row import Row
    File “C:\Python37\lib\site-packages\xlwt\Row.py”, line 7, in
    from . import ExcelFormula
    File “C:\Python37\lib\site-packages\xlwt\ExcelFormula.py”, line 3, in
    from . import ExcelFormulaParser, ExcelFormulaLexer
    File “C:\Python37\lib\site-packages\xlwt\ExcelFormulaLexer.py”, line 53, in
    VERBOSE+LOCALE+IGNORECASE)
    File “C:\Python37\lib\re.py”, line 234, in compile
    return _compile(pattern, flags)
    File “C:\Python37\lib\re.py”, line 286, in _compile
    p = sre_compile.compile(pattern, flags)
    File “C:\Python37\lib\sre_compile.py”, line 764, in compile
    p = sre_parse.parse(p, flags)
    File “C:\Python37\lib\sre_parse.py”, line 940, in parse
    p.pattern.flags = fix_flags(str, p.pattern.flags)
    File “C:\Python37\lib\sre_parse.py”, line 907, in fix_flags
    raise ValueError(“cannot use LOCALE flag with a str pattern”)
    ValueError: cannot use LOCALE flag with a str pattern

  • 问题原因
    xlwt版本较低,存在bug,需更新版本

  • 解决办法
    卸载并重装xlwt

    pip uninstall xlwt
    pip install xlwt

  • Reference
    https://github.com/kennethreitz/tablib/issues/254

你可能感兴趣的:(Python)