Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm. /usr/bin/python^M: bad interpreter [duplicate]

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?

like image 665
woozly Avatar asked Apr 02 '12 10:04

woozly


2 Answers

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.

like image 76
mmmmmm Avatar answered Oct 18 '22 08:10

mmmmmm


Set line separator to Unix:

Unix

like image 22
CrazyCoder Avatar answered Oct 18 '22 09:10

CrazyCoder