LoginSignup
66
28

More than 5 years have passed since last update.

Pythonで「SyntaxError: Non-ASCII character〜」が出てしまった時の解決法

Posted at

さっき真っさらなところからPythonファイルを作って見たところ下記のエラーが発生しました。

SyntaxError: Non-ASCII character '\xe5' in file ファイル名 on line 16, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

encodingが宣言されてないからここ見て直して、というものだったので下記URLを確認。

ページのタイトルが「Defining Python Source Code Encodings」ということで、ちゃんとencodingを定義してね、という内容でした。

よくよく自分の作ったファイルを見返してみるといきなりimportしていて、いつものおまじない文を忘れていました。

# -*- coding: utf-8 -*-

ということだったのでこちらを追加して無事解決しました。

66
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
66
28