Python source "encoding not declared"

This is the top of my source file:

# -*- coding: UTF-16 -*-
import re
import unittest

Despite including the declaration at the top of the file, I get an error when I run this: "Non-ASCII character '\xff' in file ScrapeEdgar/parsers/ on line 1, but no encoding declared; see for details".

Here's the full output:

usau810195:ScrapeEdgar reedn$ python -m unittest ScrapeEdgar.parsers.parser8kex101_tests
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 72, in _run_code
    exec code in run_globals
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 12, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 94, in __init__
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 149, in parseArgs
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 158, in createTests
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 128, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "ScrapeEdgar/parsers/", line 1
SyntaxError: Non-ASCII character '\xff' in file ScrapeEdgar/parsers/ on line 1, but no encoding declared; see  for details


Python source files don't support the UTF-16 encoding.

Any encoding which allows processing the first two lines in the way indicated above is allowed as source code encoding, this includes ASCII compatible encodings as well as certain multi-byte encodings such as Shift_JIS. It does not include encodings which use two or more bytes for all characters like e.g. UTF-16. The reason for this is to keep the encoding detection algorithm in the tokenizer simple.

See PEP 0263.

Hope this helps.


 ? How to retrive the data if it is special charecter (Õ)..?
 ? Pandas read excel with Chinese filename
 ? TextView not displaying Characters like "à è ì ò ù" in android
 ? Docker Jenkins slave wrong character encoding
 ? Same visible character but different bytes
 ? lexical error encountered: "<" (60) after ""
 ? Teradata adding  in front of special characters
 ? Adding element to dictionary breaks encoding
 ? What does this mojibake/krakozyabry on The Simpsons say?
 ? How to make Zend Form element attributes encode HTML elements using correct encoding?