WaXxX333
WaXxX333

Reputation: 486

VSCode keeps ruining Python shebangs

Every time I edit a Python script with VSC it ruins the shebang. If I manually fix it via sed or even nano, it works but if I edit anything in the script with VSC(any line) and then try to execute the script, I get the bad interpreter error ./marshal.py: bad interpreter: /bin/python3^M: no such file or directory.

Anyone have any ideas ?
Edit: So I am editing this script in Windows via VSC but executing it in WSL. Fixing the shebang in WSL works but as soon as I edit it with VSC again it breaks the shebang

Upvotes: 1

Views: 419

Answers (1)

carlfriedrich
carlfriedrich

Reputation: 4093

This is a problem with different line endings. Windows uses CRLF (carriage return + line feed) for line endings, while Linux uses LF (line feed only). The additional carriage return in your Windows-saved file is unexpected when executed in Linux and produces the given error.

VS Code displays the configured line ending for the current file in the lower right corner of the status bar:

enter image description here

Clicking on it lets you change it to LF:

enter image description here

After saving the file it is executable in a Linux environment.

Upvotes: 1

Related Questions