Shebang line on Windows?

Dave Angel davea at
Mon Feb 25 14:14:36 CET 2013

> -----Original Message-----
> From: Python-list [ at] On Behalf Of James Harris
> Sent: Friday, February 22, 2013 5:53 PM
> To: python-list at
> Subject: Re: Shebang line on Windows?
> On Feb 22, 6:40 pm, Zachary Ware <zachary.ware+pyl... at>
> A word of warning unless this has since been resolved: Whenever I have tried adding the shebang line on Windows and running it on Unix the latter has complained about the carriage return at the end of the line. This means that Unix does not work when invoked as follows.
> (And, yes, the file has had chmod +x applied.)
>    ./
> It is, of course, OK when run as
>    python
> but that removes some of the benefit of the shebang line.
> James
> --

(Fixing top-posted response, so it comes after the part it is quoting)
On 02/25/2013 07:35 AM, Sells, Fred wrote:
 > When moving from windows to unix you need to run "dos2unix"   on any
 > programs that use shebang (at least with python 2.6)   that is
 > installed on some platforms but must be installed on others like
 > CentOs but it is in their repository.

It's not Python that needs dos2unix, it's bash or equivalent.  For some 
reason, bash shebang processing still isn't tolerant of a trailing cr on 
the line. Python doesn't care.

If someone is maintaining sources that need to run on both, it's easier 
to maintain them using Unix-style newlines.  All it usually requires is 
a decent Windows text editor that honors the existing newline 
convention.  Or better that can be configured to always use simple 
newlines at end of each line.


More information about the Python-list mailing list