环境:

  • windows7
  • Python 2.7.16

在源码中添加注释之后报错如下:

(WeChat) E:\WorkHome\Wechat>python firstBlood.py
Traceback (most recent call last):
  File "firstBlood.py", line 8, in <module>
    import itchat
  File "E:\VirtualEnvs\WeChat\lib\site-packages\itchat\__init__.py", line 8
SyntaxError: Non-ASCII character '\xe5' in file E:\VirtualEnvs\WeChat\lib\site-packages\itchat\__init__.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

这是由于Python2的默认编码问题造成的,添加注释之后,需要制定编码格式,在修改文件的顶部加入以下内容:

# coding=<encoding name>

或者:

#!/usr/bin/python
# -*- coding: <encoding name> -*-

或者:

#!/usr/bin/python
# vim: set fileencoding=<encoding name> :

相关文章:

  • 2022-01-28
  • 2021-07-24
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-05-23
相关资源
相似解决方案