Run python "No such file or directory 3" or "/usr/local/bin/python3^M: bad interpreter: No such file or directory" error...

the reason

If you use #!/usr/local/bin/python3 this way, the error "/usr/local/bin/python3^M: bad interpreter: no such file or directory" will appear:

If you use #!/usr/bin/env python3 this way, there will be a "No such file or directory 3" error:

 

The reason for the error is that each line of the code has an extra 3^M at the end. This is because the code I wrote on Windows and then put it on Linux will make an error.

However, it is normal to open the code, but when you use the cat -v command to view the file, you can see that there is a ^M symbol at the end of the line.

 

solution

Run the following command, replace the ^M symbol, and regenerate a file:

cat -v oldfile.py | sed -e '1,$s/\^M$//g' > newfile.py

Then it can run normally.

Guess you like

Origin blog.csdn.net/Crystalqy/article/details/108004173