OSError: [Errno 8] Exec format error: “No such file or directory3” or “/usr/local/bin/python3^M: bad interpreter:…

Today, I encountered this problem on the Internet. Oserror: [errno 8] exec format error: I searched the Internet and found a solution. I added #, which is on the first line of Py file/ usr/bin/env python3

Continue to run or report an error, “no that file or directory 3” continue to search the Internet to find a solution


If you are using #! /usr/local/bin/python3 this way, the error "/usr/local/bin/python3^M: bad interpreter: no such file or directory" will appear.

If you are using #! /usr/bin/env python3, you get the error "No such file or directory3".

The reason for the error is that each line of the code has 3^M more at the end, which is due to the fact that I wrote the code on Windows and then put it on Linux.

However, when I open the code, it looks normal, but when I view the file with cat -v command, I can see that there is a ^M symbol at the end of each line.


Run the following command to replace the ^ m symbol and regenerate a file:

cat -v oldfile.py | sed -e '1,$s/\^M$/ /g' > newfile.py

And then it’s working


Similar Posts: