Unable to execute binary file error in python

I keep getting the following error:

$ ./test.py
-bash: ./test.py: cannot execute binary file

when trying to run the following file in python via cygwin:

#!usr/bin/python
with open("input.txt") as inf:
    try:
        while True:
            latin = inf.next().strip()
            gloss = inf.next().strip()
            trans = inf.next().strip()
            process(latin, gloss, trans)
            inf.next()    # skip blank line
    except StopIteration:
        # reached end of file
        pass
from itertools import chain

def chunk(s):
    """Split a string on whitespace or hyphens"""
    return chain(*(c.split("-") for c in s.split()))

def process(latin, gloss, trans):
    chunks = zip(chunk(latin), chunk(gloss))

How to fix it?


After accepting the suggestions below, you still get the same error.

If this helps, I tried

$ python ./test.py

and received

$ python ./test.py
  File "./test.py", line 1
SyntaxError: Non-ASCII character '\xff' in file ./test.py on line 1, but no encoding     declared; see http://www.python.org/peps/pep-0263.html for details
+3
source share
2 answers

There is a problem. You are missing the "/" before usr in #!usr/bin/python. Your line should look like this.

#!/usr/bin/python

+2
source

In addition to protecting the executable, it #!/usr/bin/pythonmay not work. At least it never worked for me on Red Hat or Ubuntu Linux. Instead, I put this in my Python files:

#!/usr/bin/env python

I do not know how this works on Windows platforms.

+1
source

All Articles