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

巧了我就是萌 提交于 2019-11-27 11:04:19

问题


This question already has an answer here:

  • ./configure : /bin/sh^M : bad interpreter [duplicate] 15 answers

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?


回答1:


Set line separator to Unix:




回答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.




回答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




回答4:


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

:set fileformat=unix



回答5:


you may want to try dos2unix <filename>




回答6:


Install dos2unix: sudo apt-get install dos2unix

and let it do the magic: dos2unix FILENAME




回答7:


For MacOS you can install it via Homebrew like this:

brew install dos2unix

And next do

dos2unix FILENAME



回答8:


Similar to Jiangwei Yu's post. On UNIX/Linux, I used vi to edit the Python file. Using vi, you can see the ^M at the end of each line.

Find the following line /usr/bin/python^M

Hit end to get to the end of the line

Hit delete to remove the ^M

To save the file and quit, type in: :wq

This worked for me.




回答9:


you may try to do this:

sed --in-place 's/^M//g' main.py

[ to type in ^M, press ctrl+v,ctrl+m ]




回答10:


Just a Question of format beween win and unix:

try command: dos2unix fileName

After it run again, it should work



来源:https://stackoverflow.com/questions/9975011/pycharm-usr-bin-pythonm-bad-interpreter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!