Shebang line on Windows?

Chris Gonnerman chris at
Mon Feb 25 14:28:53 CET 2013

On 02/25/2013 06: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.
Or edit it in Vim and do

:se ff=unix

and then save it.

dos2unix is handy if you don't plan to edit the file for any other 
reason.  I'm assuming other editors provide similar features, but I've 
been a vi/vim user FOREVER.

Or, borrowed from a Stack Overflow thread here:

|sed 's/\r\n$/\n/' >|

> -----Original Message-----
> From: Python-list [ at] On Behalf Of James Harris
> Sent: Friday, February 22, 2013 5:53 PM
> To: python-list at
> Subject: [Python] Re: Shebang line on Windows?
> On Feb 22, 6:40 pm, Zachary Ware <zachary.ware+pyl... at>
> wrote:
>> On Fri, Feb 22, 2013 at 12:16 PM, Walter Hurry <walterhu... at> wrote:
>>> I use FreeBSD or Linux, but my son is learning Python and is using
>>> Windows.
>>> My question is this: Would it be good practice for him to put
>>> #!/usr/bin/ env python at the top of his scripts, so that if made
>>> executable on *nix they will be OK? As I understand it this will
>>> have no effect on Windows itself.
>> Adding the shebang line on Windows would be excellent practice.
> 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
> --

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list