Phenomenon:
Copy a normal py file, modify part of the code, save and execute Python demo.py. An error message appears: syntax error: non-utf-8 code starting with ‘\ xe7’
reason:
The text encoding copied elsewhere may not be utf8
Solution 1:
Python 3 uses UTF-8 format by default
Generally, you don’t need to add it at the beginning # -*- coding:utf-8 -*-
However, some Chinese characters are still unrecognized and throw non-utf-8 code starting with ‘\ xe7’ If you are wrong, you need to add this sentence to the first line.
# -*- coding:utf-8 -*-
Solution 2:
Python 3 demo.py so that there will be no error prompt during execution
Solution 3:
Click the encoding UTF-8 in the lower right corner of vscode, save the current file as UTF-8, and then execute Python demo.py without error prompt.
Similar Posts:
- Solutions to Python Chinese annotation errors
- Solutions to Python Chinese annotation errors
- [Solved] Python pip install Error: SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xc6
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1:
- SyntaxError: Non-ASCII character ‘\xe2‘ in file
- [Solved] SSH Remote execute Python 3 error: Unicode encodeerror: ‘ASCII’ codec
- Mac Python3 Conda Pytorch Error: libc++abi.dylib: terminating with uncaught exception of type NSException
- [Solved] Typeerror: incorrect padding occurred in python3 Base64 decoding
- Error in reading Chinese path of pydev in eclipse
- [Solved] Pandas Parses MovieLens 1M Dataset Error: UnicodeDecodeError