PyCharm。/usr/bin/python ^ M:糟糕的翻译(复制)

时间:2022-10-13 20:45:05

This question already has an answer here:

这个问题已经有了答案:

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):

输出类似这样的东西,当我尝试运行它时,像可执行文件(chmode +x):

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

bash:。/主要。py: /usr/bin/python M:坏翻译:没有这样的文件或目录。

What to do and how to be?

该做什么,怎么做?

10 个解决方案

#1


27  

Set line separator to Unix:

设置行分隔符到Unix:

PyCharm。/usr/bin/python ^ M:糟糕的翻译(复制)

#2


33  

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 .

这个问题不是EOF,而是EOL。壳牌认为^ M以及行结束,从而试图找到/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.

进入这个状态的通常方法是用MSDOS/Windows编辑器编辑python文件,然后在Unix上运行。最简单的解决方法是在文件上运行dos2unix,或者在编辑器中编辑该文件,该编辑器显式地允许使用Unix行结束保存。

#3


16  

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

你可以在这里找到答案:. / configure:/bin/sh ^ M:糟糕的翻译

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

作为一个Mac OS X用户,我没有找到命令dos2unix。或者,我使用vi/vim::set fileformat=unix,然后保存文件:wq。

#4


9  

you may want to try dos2unix <filename>

您可能想尝试dos2unix

#5


6  

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

如果您正在使用Vim,请输入以下命令:

:set fileformat=unix

#6


5  

Install dos2unix: sudo apt-get install dos2unix

安装dos2unix: sudo apt-get安装dos2unix。

and let it do the magic: dos2unix FILENAME

并让它发挥魔力:dos2unix文件名。

#7


3  

For MacOS you can install it via Homebrew like this:

对于MacOS,你可以通过Homebrew来安装它:

brew install dos2unix

And next do

和下一个

dos2unix FILENAME

#8


1  

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.

类似于姜维瑜的帖子。在UNIX/Linux上,我使用vi来编辑Python文件。使用vi,你可以看到每一行的末尾有个M。

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

找到以下行/usr/bin/python ^ M

Hit end to get to the end of the line

点击结束,到达线的末端。

Hit delete to remove the ^M

点击删除删除^ M

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

要保存文件并退出,请键入::wq。

This worked for me.

这为我工作。

#9


1  

you may try to do this:

你可以试着这样做:

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

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

(输入^ M,按ctrl + v,ctrl + M]

#10


0  

Just a Question of format beween win and unix:

关于win和unix的格式问题:

try command: dos2unix fileName

试着命令:dos2unix文件名

After it run again, it should work

在它再次运行之后,它应该工作。

#1


27  

Set line separator to Unix:

设置行分隔符到Unix:

PyCharm。/usr/bin/python ^ M:糟糕的翻译(复制)

#2


33  

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 .

这个问题不是EOF,而是EOL。壳牌认为^ M以及行结束,从而试图找到/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.

进入这个状态的通常方法是用MSDOS/Windows编辑器编辑python文件,然后在Unix上运行。最简单的解决方法是在文件上运行dos2unix,或者在编辑器中编辑该文件,该编辑器显式地允许使用Unix行结束保存。

#3


16  

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

你可以在这里找到答案:. / configure:/bin/sh ^ M:糟糕的翻译

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

作为一个Mac OS X用户,我没有找到命令dos2unix。或者,我使用vi/vim::set fileformat=unix,然后保存文件:wq。

#4


9  

you may want to try dos2unix <filename>

您可能想尝试dos2unix

#5


6  

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

如果您正在使用Vim,请输入以下命令:

:set fileformat=unix

#6


5  

Install dos2unix: sudo apt-get install dos2unix

安装dos2unix: sudo apt-get安装dos2unix。

and let it do the magic: dos2unix FILENAME

并让它发挥魔力:dos2unix文件名。

#7


3  

For MacOS you can install it via Homebrew like this:

对于MacOS,你可以通过Homebrew来安装它:

brew install dos2unix

And next do

和下一个

dos2unix FILENAME

#8


1  

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.

类似于姜维瑜的帖子。在UNIX/Linux上,我使用vi来编辑Python文件。使用vi,你可以看到每一行的末尾有个M。

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

找到以下行/usr/bin/python ^ M

Hit end to get to the end of the line

点击结束,到达线的末端。

Hit delete to remove the ^M

点击删除删除^ M

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

要保存文件并退出,请键入::wq。

This worked for me.

这为我工作。

#9


1  

you may try to do this:

你可以试着这样做:

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

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

(输入^ M,按ctrl + v,ctrl + M]

#10


0  

Just a Question of format beween win and unix:

关于win和unix的格式问题:

try command: dos2unix fileName

试着命令:dos2unix文件名

After it run again, it should work

在它再次运行之后,它应该工作。