A Python script written under Windows system that is given permissions under Linux chmod +x xxx.py after execution./xxx.py run prompt: bash:/usr/bin/autocrorder:/usr/bin/python^m: Bad interpreter:no such file or directory
Analysis:
This is caused by different system encoding formats: the. Sh. py file that is edited in the Windows system may have invisible characters, so it will report the above exception information in the Linux system. This is typically caused by a difference between the end of the Windows line and the end of the Linux line.
Solve:
1 conversion under Windows:
Use tools such as UltraEdit or editplus to convert scripts to code and then execute them in Linux. The conversion method is as follows (UltraEdit): File-->conversions-->dos->unix.
2) direct replacement under Linux:
Sed-i ' s/^m//g ' filename (note that ^m is written under Linux by ^m is a carriage return line feed, the input method is to hold down CTRL + V, Release v., press M)
3) can also be converted in Linux:
First, make sure the file has executable permissions
Copy Code code as follows:
Then modify the file format
Copy Code code as follows:
Use the following command to view file formats
: 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 (Disk exit)
Final File Execution
#sh >./filename