在emacs编辑python文件中带有中文会报错,但是不会影响程序在ipython运行



Entering debugger...
Suspicious state from syntax checker python-flake8: Flycheck checker python-flake8 returned 1, but its output contained no errors: Traceback (most recent call last):
  File "d:\python\lib\site-packages\flake8\utils.py", line 207, in stdin_get_value
    return io.TextIOWrapper(fd, coding).read()
  File "d:\python\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 13: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "d:\python\lib\runpy.py", line 208, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "d:\python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\python\lib\site-packages\flake8\__main__.py", line 4, in <module>
    cli.main()
  File "d:\python\lib\site-packages\flake8\main\cli.py", line 22, in main
    app.run(argv)
  File "d:\python\lib\site-packages\flake8\main\application.py", line 375, in run
    self._run(argv)
  File "d:\python\lib\site-packages\flake8\main\application.py", line 364, in _run
    self.run_checks()
  File "d:\python\lib\site-packages\flake8\main\application.py", line 269, in run_checks
    self.file_checker_manager.start(files)
  File "d:\python\lib\site-packages\flake8\checker.py", line 324, in start
    self.make_checkers(paths)
  File "d:\python\lib\site-packages\flake8\checker.py", line 224, in make_checkers
    for argument in paths
  File "d:\python\lib\site-packages\flake8\checker.py", line 228, in <listcomp>
    if should_create_file_checker(filename, argument)
  File "d:\python\lib\site-packages\flake8\checker.py", line 357, in __init__
    self.processor = self._make_processor()
  File "d:\python\lib\site-packages\flake8\checker.py", line 371, in _make_processor
    return processor.FileProcessor(self.filename, self.options)
  File "d:\python\lib\site-packages\flake8\processor.py", line 75, in __init__
    self.lines = lines if lines is not None else self.read_lines()
  File "d:\python\lib\site-packages\flake8\processor.py", line 334, in read_lines
    lines = self.read_lines_from_stdin()
  File "d:\python\lib\site-packages\flake8\processor.py", line 352, in read_lines_from_stdin
    return utils.stdin_get_lines()
  File "d:\python\lib\site-packages\flake8\utils.py", line 214, in stdin_get_lines
    return list(io.StringIO(stdin_get_value()))
  File "d:\python\lib\site-packages\flake8\utils.py", line 209, in stdin_get_value
    return stdin_value.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 13: invalid start byte

Try installing a more recent version of python-flake8, and please open a bug report if the issue persists in the latest release.  Thanks!
Beginning of buffer [8 times]
elpy-promise-reject: peculiar error: "exited abnormally with code 1"
Suspicious state from syntax checker python-flake8: Flycheck checker python-flake8 returned 1, but its output contained no errors: Traceback (most recent call last):
  File "d:\python\lib\tokenize.py", line 385, in find_cookie
    line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 7: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python\lib\site-packages\flake8\utils.py", line 205, in stdin_get_value
    coding, _ = tokenize.detect_encoding(fd.readline)
  File "d:\python\lib\tokenize.py", line 426, in detect_encoding
    encoding = find_cookie(first)
  File "d:\python\lib\tokenize.py", line 390, in find_cookie
    raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "d:\python\lib\runpy.py", line 208, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "d:\python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\python\lib\site-packages\flake8\__main__.py", line 4, in <module>
    cli.main()
  File "d:\python\lib\site-packages\flake8\main\cli.py", line 22, in main
    app.run(argv)
  File "d:\python\lib\site-packages\flake8\main\application.py", line 375, in run
    self._run(argv)
  File "d:\python\lib\site-packages\flake8\main\application.py", line 364, in _run
    self.run_checks()
  File "d:\python\lib\site-packages\flake8\main\application.py", line 269, in run_checks
    self.file_checker_manager.start(files)
  File "d:\python\lib\site-packages\flake8\checker.py", line 324, in start
    self.make_checkers(paths)
  File "d:\python\lib\site-packages\flake8\checker.py", line 224, in make_checkers
    for argument in paths
  File "d:\python\lib\site-packages\flake8\checker.py", line 228, in <listcomp>
    if should_create_file_checker(filename, argument)
  File "d:\python\lib\site-packages\flake8\checker.py", line 357, in __init__
    self.processor = self._make_processor()
  File "d:\python\lib\site-packages\flake8\checker.py", line 371, in _make_processor
    return processor.FileProcessor(self.filename, self.options)
  File "d:\python\lib\site-packages\flake8\processor.py", line 75, in __init__
    self.lines = lines if lines is not None else self.read_lines()
  File "d:\python\lib\site-packages\flake8\processor.py", line 334, in read_lines
    lines = self.read_lines_from_stdin()
  File "d:\python\lib\site-packages\flake8\processor.py", line 352, in read_lines_from_stdin
    return utils.stdin_get_lines()
  File "d:\python\lib\site-packages\flake8\utils.py", line 214, in stdin_get_lines
    return list(io.StringIO(stdin_get_value()))
  File "d:\python\lib\site-packages\flake8\utils.py", line 209, in stdin_get_value
    return stdin_value.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 7: invalid start byte

Try installing a more recent version of python-flake8, and please open a bug report if the issue persists in the latest release.  Thanks!

Windows下面试试修改Emacs的默认编码为UTF-8

(set-default-coding-systems 'utf-8-unix)
(set-buffer-file-coding-system 'utf-8-unix)

谢谢老哥!----