PyCharm. /usr/bin/python^M: bad interpreter

103,608

Solution 1

Set line separator to Unix:

Unix

Solution 2

The issue is not EOF but EOL. The shell sees a ^M as well as the end of line and thus tries to find /usr/bin/python^M .

The usual way of getting into this state is to edit the python file with a MSDOS/Windows editor and then run on Unix. The simplest fix is to run dos2unix on the file or edit the file in an editor that explicitly allows saving with Unix end of lines.

Solution 3

You may find the answers here: ./configure : /bin/sh^M : bad interpreter

As a Mac OS X user, I didn't find the command dos2unix. Alternatively, I use vi/vim: :set fileformat=unix and then save the file :wq

Solution 4

If you are using Vim, just enter the following command:

:set fileformat=unix

Solution 5

you may want to try dos2unix <filename>

Share:
103,608
woozly
Author by

woozly

Updated on July 08, 2022

Comments

  • woozly
    woozly almost 2 years

    Cannot figure out, where to change EOF in PyCharm. My scripts, started with:

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    

    Outputs something like this, when I try to run it like executable (chmode +x):

    -bash: ./main.py: /usr/bin/python^M: bad interpreter: No such file or directory

    What to do and how to be?