Fix Python SyntaxError: Non-ASCII character ‘\xe4’ in file Error – Python Tutorial

By | August 19, 2022

When we are running python script on terminal, we may get this error: SyntaxError: Non-ASCII character ‘\xe4’ in file. In this tutorial, we will introduce you how to fix it.

For example:

We run a python like below:

python train_model.py

Then, we see this error:

Fix Python SyntaxError: Non-ASCII character '\xe4' in file Error - Python Tutorial

How to fix this SyntaxError?

Here are two methods.

Method 1: remove all Non-ASCII characters

In this example, we can find Non-ASCII character on line 39. We can find this line in train_model.py and remove them.

Remove Non-ASCII characters in python file

However, this may not be a good method. Sometimes, we have to add some Non-ASCII characters in python script.

Method 2: add code below at the top of your python script.

For example:

# -*- coding: utf-8 -*

Run this python script again, we will find this error is fixed.

Leave a Reply