1

So, I read PLENTY of questions and every single one of them forgot to put # coding: <encoding> string in start, or something like that.

My problem is this, chronologically.

1) I forgot to put encoding too, while working with cyrillic literals

2) I put it: didn't work

3) I put from __future__ import unicode_literals Still doesn't works.

4) I commented out string, which caused it. Didn't work. Shocked.

5) I rolled back (manually) to previous version of mine, deleted all changes completely. Don't work.

So, this is my traceback, and in 1st line I only have import tweepy which clearly doesn't have any unicode literals (deleted shebang in process of finding the cause of issue)

    Traceback (most recent call last):
  File "E:\Coding\PyCharm 3.1\helpers\pydev\pydevd.py", line 1534, in <module>
    debugger.run(setup['file'], None, None)
  File "E:\Coding\PyCharm 3.1\helpers\pydev\pydevd.py", line 1145, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
  File "C:/Users/tibur_000/PycharmProjects/Twelcome/TWelcome.py", line 1
SyntaxError: Non-ASCII character '\xfe' in file
C:/Users/tibur_000/PycharmProjects/Twelcome/TWelcome.py on line 1,
but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Delimitry
  • 2,987
  • 4
  • 30
  • 39
wyde19
  • 408
  • 3
  • 13
  • Your source code appears to contain a `\xfe` byte on the first line. That's usually due to a [`\xfe\xff` UTF-16 big-endian BOM character](http://en.wikipedia.org/wiki/Byte_order_mark#Representations_of_byte_order_marks_by_encoding) at the start of your file. Did you save the sourcecode as UTF16 perhaps? – Martijn Pieters Jul 10 '14 at 12:50
  • What does PyDev say the encoding for the file is? Also see http://www.jetbrains.com/pycharm/webhelp/configuring-individual-file-encoding.html#edit – Martijn Pieters Jul 10 '14 at 12:51
  • @MartijnPieters okay, i have not a clue, why that happened, but it seems PyCharm converted it at some point indeed. I converted it back with the help of your link. Much obliged. – wyde19 Jul 10 '14 at 12:56

1 Answers1

1

It looks like your file starts with the BOM character; you probably saved the file in a UTF encoding.

If you are not actually using non-ASCII text in your source, you may want to switch back to using the ASCII encoding for your file. Otherwise, you'll have to specify the UTF codec used in a PEP 263 codec declaration.

However, if it is using UTF-16 or UTF-32, pick a different codec. Python 2 does not support source code encoded to these encodings.

In PyCharm, you can alter the encoding used for individual files via the File > File encoding menu option or the status bar. See the PyCharm help information

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343