Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 14866  / 2 Years ago, mon, march 28, 2022, 2:17:41

Lubuntu Raring Ringtail. I want to be able to execute my scripts with ./



I start my python script with #!/usr/bin/python and it says



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


If I use #!/usr/bin/env python it gives a similar error:



: No such file or directory


What am I doing wrong?



I absolutely have python installed, and can run the scripts as normal with python myscript.py


More From » bash

 Answers
6

From the ^M you can see that the file myscript.py is using windows/dos-style line breaks (Windows uses CR LF (carriage return + line feed) at the end of a line. Unix only uses LF - so what you see as ^M is the CR. So what you are not using /usr/bin/python but /usr/bin/python<CR> that does not exist.



You can remove the ^M using dos2unix (do a sudo apt-get install dos2unix to install and then use dos2unix myscript.py).


[#29926] Monday, March 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
skipu

Total Points: 366
Total Questions: 114
Total Answers: 112

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
;