making a python program in windows

Discussion in 'Python' started by Rustom Mody, May 21, 2009.

  1. Rustom Mody

    Rustom Mody Guest

    I know how to make a python script behave like a (standalone) program
    in unix --
    1. put a #! path/to/python as the first line
    2. make the file executable

    The closest I know how to do this in windows is:
    r-click the file in win-explorer
    goto properties
    goto open with
    change pythonw to python

    Can someone enlighten me about a more scriptish way of doing this?
    Basically if I have to setup that program on other (windows) m/cs is
    there some .bat or .vbs or some regedit thingy Ive to do to avoid the
    Rt-click routine?
     
    Rustom Mody, May 21, 2009
    #1
    1. Advertising

  2. Rustom Mody

    rustom Guest

    On May 21, 3:19 pm, "Martin P. Hellwig" <>
    wrote:
    > Rustom Mody wrote:
    > > I know how to make a python script behave like a (standalone) program
    > > in unix --
    > > 1. put a #! path/to/python as the first line
    > > 2. make the file executable

    >
    > > The closest I know how to do this in windows is:
    > > r-click the file in win-explorer
    > > goto properties
    > > goto open with
    > > change pythonw to python

    >
    > > Can someone enlighten me about a more scriptish way of doing this?
    > > Basically if I have to setup that program on other (windows) m/cs is
    > > there some .bat or .vbs or some regedit thingy Ive to do to avoid the
    > > Rt-click routine?

    >
    > Since you don't know for sure if a Python environment is available on
    > the other windows machine and whether the file associations are
    > configured correctly, the best thing you can do is to use something like
    > py2exe and distribute the result of that.


    Oh - Oh! Not an exe please! I dont want to move away from readable
    text files if possible.

    I certainly know that python2.6 is installed.
    Why that installation by default does not put python.exe on the path I
    dont know but that is best corrected by hand.

    Bottom Line: Assume that from a command line (cmd) python runs and
    gives its interpreter prompt.
    When run from cygwin it hangs but thats another story. Just dont
    assume cygwin.

    i suppose the question is entirely about setting properly (and
    grokking) file associations -- why is a .py file associated with
    pythonw and not python? And is making this association right enough to
    make a .py file in windows behave like a shebang file in unix?

    [And is there a more appropriate list for such questions?]

    Thanks
     
    rustom, May 21, 2009
    #2
    1. Advertising

  3. Rustom Mody

    rustom Guest

    On May 21, 5:09 pm, Duncan Booth <> wrote:
    > rustom <> wrote:
    > > i suppose the question is entirely about setting properly (and
    > > grokking) file associations -- why is a .py file associated with
    > > pythonw and not python? And is making this association right enough to
    > > make a .py file in windows behave like a shebang file in unix?

    >
    > I think the question about the file association is one you have to answer
    > for yourself. When you install Python it associates .pyw with pythonw and
    > .py with python. If something on your system has changed this the best
    > thing you can do is to change it back.
    >
    > Try typing the following commands and then fixing any differences by typing
    > the expected output as the command parameter
    > (e.g. "assoc .py=Python.File"):
    >
    > C:\>assoc .py
    > .py=Python.File
    >
    > C:\>assoc .pyw
    > .pyw=Python.NoConFile
    >
    > C:\>ftype Python.file
    > Python.file="C:\Python26\python.exe" "%1" %*
    >
    > C:\>ftype Python.NoConFile
    > Python.NoConFile="C:\Python26\pythonw.exe" "%1" %*
    >
    > --
    > Duncan Boothhttp://kupuguy.blogspot.com


    Thanks for this (and all other) tips.
    Strangely now my m/c shows things exactly like so. A new .py file gets
    associated with python but two days ago it was with pythonw?!
    Any recos on where I could read up on this stuff?
     
    rustom, May 22, 2009
    #3
  4. Rustom Mody

    Tim Golden Guest

    rustom wrote:
    > Thanks for this (and all other) tips.
    > Strangely now my m/c shows things exactly like so. A new .py file gets
    > associated with python but two days ago it was with pythonw?!
    > Any recos on where I could read up on this stuff?


    I by "all this stuff" you mean: Windows file associations,
    then this would be the place:

    http://msdn.microsoft.com/en-us/library/dd758090(VS.85).aspx

    If you mean: what the Python installer does to set such
    things up, then there is some information here:

    http://docs.python.org/using/windows.html

    but not really covering the exact question you've
    been asking. You'd have to hunt around the archives
    of this mailing list and/or look at the msi source:

    http://svn.python.org/view/python/trunk/Tools/msi/msi.py?view=markup

    (and feel free to submit a doc patch if you think it might help)

    TJG
     
    Tim Golden, May 22, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    1,938
    Andrew Thompson
    Jan 12, 2005
  2. rfractal30
    Replies:
    7
    Views:
    407
    Rogan Dawes
    Jan 17, 2005
  3. pradeep nair
    Replies:
    2
    Views:
    578
  4. Stef Mientki
    Replies:
    0
    Views:
    361
    Stef Mientki
    Nov 1, 2009
  5. CWC
    Replies:
    3
    Views:
    335
    Sridhar Ratnakumar
    Nov 8, 2010
Loading...

Share This Page