Tag Archives: /usr/bin/python^M: bad interpreter: No such file or directory

[Solved] Python Error: /usr/bin/python^M: bad interpreter: No such file or directory

The main reason is ^ M

This is caused by different system coding formats: the. Sh. Py file edited in Windows system may have invisible characters, so the above abnormal information will be reported when executing in Linux system. It is usually caused by the different identification of the end of windows line and Linux line

Solution:

1) Conversion in Windows:

Use some editors, such as UltraEdit or EDITPLUS, to encode and convert scripts first, and then put them into Linux for execution. The conversion method is as follows (UltraEdit): File — > Conversions–> DOS-> UNIX is fine

2) Direct replacement under Linux

Sed – I’s/^ m// g ‘file name

3) It can also be converted in Linux

First, make sure that the file has executable permissions

#sh> chmod a+x filename

Then change the file format

#sh> vi filename

Use the following command to view the file format

: set FF or: set fileformat

You can see the following information

Fileformat = DOS or fileformat = UNIX

Use the following command to modify the file format

: set FF = UNIX or: set fileformat = UNIX

: WQ (save and exit)

Finally, execute the file

#sh>./ filename