Home > Python > Python SyntaxError: Non-ASCII character ‘\xe2′ in file

Python SyntaxError: Non-ASCII character ‘\xe2′ in file

When executing a python script you get the following error:

SyntaxError: Non-ASCII character ‘\xe2′ in file pro.py on line 11, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Solution:

Add the below line at top of the .py file

# coding: utf-8

About these ads
Categories: Python
  1. Niko
    July 13, 2010 at 10:52 pm

    For eclipse unicode console support:

    1. Add -Dfile.encoding=UTF-8 to eclipse.ini which is in the eclipse install directory.
    2. In eclipse – Run\Run Configurations\Python Run\configuration\Common\make sure UTF-8 is selected
    3. In eclipse – Window\Preferences\General\Workspace\Text file encoding\making sure UTF-8 is selected
    4. In [python install path]\Lib\site.py – chane from encoding = “ascii” to encoding = “utf-8″
    5. Make sure you’re using unicode supporting fonts in eclipse – Window\Preferences\Appearance\Colors and Fonts\Debug\Console font\Edit

  2. August 2, 2010 at 12:34 pm

    Thanks @Niko

  3. Hank
    May 18, 2011 at 3:32 am

    I ran into a similar error that wasn’t solved by either of the above solutions. What did help was adding u to the front of the relevant “strings” (u”strings”) to force python to use unicode.

  4. jp
    July 15, 2011 at 11:03 am

    its working in unix platform..thanks..

  5. November 28, 2011 at 3:50 pm

    thanks for the solution!!
    CC

  6. siddharth
    June 22, 2012 at 10:00 am

    Thanks it did the task

  7. jdoe
    July 8, 2012 at 5:53 am

    yes, on windows
    you need to include the entire below at top of the file:
    # -*- coding: utf-8 -*-

    As per http://www.python.org/dev/peps/pep-0263/

  8. morrie
    July 20, 2012 at 3:58 pm

    thanks!!
    I solve the bug finally~

  9. February 7, 2013 at 8:24 pm

    Thank you very much!!!!!!

  10. April 19, 2013 at 7:43 am

    Great items from you, man. I have be aware your stuff previous to and you’re just extremely great. I really like what you’ve obtained right here, certainly like what you’re stating and the way in which wherein you say it. You are making it entertaining and you still care for to stay it wise. I can not wait to read much more from you. That is really a wonderful website.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 215 other followers

%d bloggers like this: