Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"cannot execute binary file" error in python

Tags:

python

cygwin

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 do I fix this??


After taking on the below suggestions, still getting the same error.

If this helps, I tried

$ python ./test.py

and got

$ 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
like image 750
user1374310 Avatar asked May 05 '12 08:05

user1374310


People also ask

How do I fix cannot execute a binary file on Ubuntu?

How to Fix ‘cannot execute binary file: Exec format error’ on Ubuntu. If the issue is with your Computer or a Laptop you should try using Restoro which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption.

Why do binary programs fail to execute properly?

Rather, this is simply because the compiled microprocessor opcode inside of the binary is so alien to your system that it doesn’t know how to interpret some of the code. The best way to fix this is to install the proper package for your architecture.

Why can't I run a binary on my Mac?

If you've downloaded a binary and executing it fails with this error, check if you've downloaded the version for the wrong OS. Show activity on this post. For me, copying the binary into Applications on my Mac then into my Path messed it up on my Mac.

Why can't I run a python script from a container?

The command your container is running is probably something like So bash finds a python in its $PATH (successfully), and tries to run it as a shell script (leading to that error). You don't strictly need an ENTRYPOINT, and here it's causing trouble.


2 Answers

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

#!/usr/bin/python

like image 62
kofemann Avatar answered Sep 28 '22 09:09

kofemann


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

#!/usr/bin/env python

I don't know how this works on Windows platforms.

like image 40
octopusgrabbus Avatar answered Sep 28 '22 07:09

octopusgrabbus