First, install the XLRD and XLWT function module steps
1. Use python-v to view the Python version number and to see if the installation was successful, 2. Available via official website (python: https://pypi.python.org/ PyPI) or other means to obtain the installation package of the function module; 3. Unzip the package and place it under the Python->lib file
4. In the CMD Command window, enter the E:\Python\Python36\Lib directory, enter the directory of XLRD and XLWT respectively, execute Python setup.py install command;
5. In the Python tool, execute import xlwt3 and import xlrd, the operation result is not error, prove the installation is successful;
Two
The solution to the error when using XLWT
1. Import XLWT3 Error: Valueerror:cannot use LOCALE flags with a str pattern
detailed error message: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 workaround: Go to the E:\Python\Python36\Lib\sre_parse.py file and modify the code: &NBSP;IF Flags & Sre_flag_locale:
Pass #stone20170712 Raise ValueError ("Cannot use LOCALE flag with a str pattern") executes import xlwt3, results OK
2. Import xlwt3 Error: ValueError: ' __init__ ' in __slots__ conflicts with class variable
detailed error message: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 solution: Enter e:\ python\python36\lib\site-packages\xlwt3\formula.py file, place the __slots__ = [ "__init__", "__s", " __parser ", " __sheet_refs ", " __xcall_refs "] modified to: __slots__ = [" __s ", " __parser ", " _ _sheet_refs ", " __xcall_refs "] execute import xlwt3, result ok
Steps to install XLRD and XLWT in Python and workarounds for using errors