0
点赞
收藏
分享

微信扫一扫

Python学习笔记(1)~Vscode中Python报错:Non-ASCII character ‘\xe7‘ in file.....


报错代码

#第一个python程序
print("hello worcld")

报错原因:

SyntaxError: Non-ASCII character '\xe7' in file /Users/haihong/代码/python/helloworld/hello.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

原因

python的默认编码文件是ASCII码,而在自己的python文件中使用了中文等非英文字符。

解决方法

方法1.加入 #coding=UTF-8或者 #coding:UTF-8

#coding=UTF-8 
#第一个python程序
print("hello world")

运行结果

Python学习笔记(1)~Vscode中Python报错:Non-ASCII character ‘\xe7‘ in file....._vscode


方法2.加入#-- coding:UTF-8 –

#-- coding:UTF-8 --
#第一个python程序
print("hello world")

方法3.加入# - * - coding: utf-8 -*-

# -*- coding: utf-8 -*-
#第一个python程序
print("hello world")

方法4.加入# vim: set fileencoding=utf-8 :

# vim: set fileencoding=utf-8 :
#第一个python程序
print("hello wcorld")

方法5.加入#!/usr/bin/python3

#!/usr/bin/python3
#第一个python程序
print("hello wcorld")



举报

相关推荐

Python学习笔记(1)

0 条评论