Scripting Python script under Windows error running under Linux Usr/bin/python^m:bad interpreter:no such file or directory

Source: Internet
Author: User
Tags python script ultraedit

Today, using notepad++ to write a Python script under Windows, to the Linux server after the execution prompt:-bash:./logger.py:usr/bin/python^m:bad interpreter:no Such File or directory

1. Cause Analysis
this is caused by different system encoding formats: The logger.py file edited in the Windows system may have invisible characters, so the above exception information is reported in the Linux system execution. This is generally due to the fact that the end of the Windows line and the end of the Linux line are different, the end of the row in the window is the ' \ r \ n ' table, and the end character in Linux is ' \ n ', and ^m is the ' \ R ' in ASCII.

2. Workaround
1) Convert under Windows:
use some editors, such as UltraEdit or EditPlus, to first convert the script encoding and then put it into Linux for execution. The conversion mode is as follows (UltraEdit): File-->conversions-->dos->unix.
2) Direct replacement under Linux:
sed-i ' s/^m//g ' filename, meaning to replace the ^m in each row of the filename is/(note ^m in Linux, press ^m is the carriage return newline character, the input method is to press CTRL + V, Loosen v., press M)
3) can also be converted in Linux:
first, make sure the file has executable permissions: chmod a+x filename, then modify the file format: VI filename, then use the set FF (or set FileFormat) command to view the file format for Fileformat=dos or Fileformat=unix;
then use the following command to modify the file format: Set Ff=unix or: Et Fileformat=unix, last Wq (save exit)
Finally, execute the file again./filename

Windows Write Python script error running under Linux Usr/bin/python^m:bad interpreter:no such file or directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.