執行Python程序出現“SyntaxError: Non-UTF-8 code starting with '\xb6'...”錯誤怎么辦?


如果文件中有中文,直接執行python xx.py會出現以下錯誤:

SyntaxError: Non-UTF-8 code starting with '\xb6' in file XX.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

要解決也好辦。直接在文件頭處加 #encoding=utf-8 就行了。如下圖:

 

附:以前3.7的時候不檢查這個的,到了3.8多一事了。

--2020年1月31日--


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM