当使用Spyder执行python代码时
name ='孙悟空'
print('欢迎' +name+'光临!')
然后就报错:
解决办法是:
1.找到你Anaconda安装的路径,找到 spydercustomize.py文件。
C:\ProgramData\Anaconda3\Lib\site-packages\spyder_kernels\customize
2.编辑该文件:增加 encoding='utf-8'
def get_file_code(filename):
"""Retrive the content of a file."""
# Get code from spyder
try:
file_code = frontend_request().get_file_code(filename)
except (CommError, TimeoutError):
file_code = None
if file_code is None:
with open(filename, 'r',encoding='utf-8') as f:#增加 ,encoding='utf-8'
return f.read()
return file_code
3.重启Spyder 重新执行代码:一切okay