How to make python scripts .py executable, not bring up editor

Discussion in 'Python' started by korean_dave, Jul 7, 2008.

  1. korean_dave

    korean_dave Guest

    From command Prompt, i type in a script, "tryme.py".

    This, instead, brings up PythonWin editor and Interactive Window.

    Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)

    How do I make it so that the script runs?
     
    korean_dave, Jul 7, 2008
    #1
    1. Advertising

  2. korean_dave

    norseman Guest

    korean_dave wrote:
    >>From command Prompt, i type in a script, "tryme.py".

    >
    > This, instead, brings up PythonWin editor and Interactive Window.
    >
    > Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >
    > How do I make it so that the script runs?
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >

    ======================================
    I get tired of Microsoft jerking me around too. Rather than spend hours
    trying to undo somebody's reorganizing my system preferences I just
    ignore them completely.

    py tryme is how I do it.

    py.bat is a file placed in a directory listed in PATH in autoexec.bat.
    Edit autoexec.bat to include directory you put it in and reboot system
    or it won't find it. something like: PATH=.;c:\py-stuff;[anything
    already listed] Don't forget the semicolons.

    The . (period) up front means look here first. here being where ever you
    are when you issued the command. (The pRESENT wORKING dIRECTORY :) The
    c:\py-stuff (fix to suit yourself and make sure it exists) is where you
    can put your efforts to be called at your leisure. Your .py files you
    write and use. Even the py.bat can go there.

    (Short note: Microsoft usually does look in pwd first. But good form
    dictates being specific.)

    contents of py.bat:
    ========================
    rem name: py.bat
    @echo off
    c:\Python24\python %f.py make it fit your path
    rem end of file
    ========================

    This way - you get what you expect, when you expect it, & nothing else.
    Yeah - dumb, but it works! I have one similar for each of my compilers.
    They contain the whole command line switches stuff as well as things
    like remove old stuff before trying to over write with new since MS can
    be temperamental about that.

    Easiest way in the world to give it the finger and make it behave.

    Steve
     
    norseman, Jul 8, 2008
    #2
    1. Advertising

  3. korean_dave

    Grumman Guest

    korean_dave wrote:
    > From command Prompt, i type in a script, "tryme.py".
    >
    > This, instead, brings up PythonWin editor and Interactive Window.
    >
    > Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >
    > How do I make it so that the script runs?


    Start-><right click>My Computer->Properties->Advanced->Environment Variables

    in bottom pane "System Variables" add ";.py" to "PATHEXT"
     
    Grumman, Jul 8, 2008
    #3
  4. korean_dave

    Paul McGuire Guest

    On Jul 7, 4:56 pm, korean_dave <> wrote:
    > From command Prompt, i type in a script,  "tryme.py".
    >
    > This, instead, brings up PythonWin editor and Interactive Window.
    >
    > Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >
    > How do I make it so that the script runs?


    type:

    python tryme.py

    or:

    C:\Python24\python tryme.py

    -- Paul
     
    Paul McGuire, Jul 8, 2008
    #4
  5. korean_dave

    Iain King Guest

    On Jul 7, 10:56 pm, korean_dave <> wrote:
    > From command Prompt, i type in a script,  "tryme.py".
    >
    > This, instead, brings up PythonWin editor and Interactive Window.
    >
    > Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >
    > How do I make it so that the script runs?


    find a .py file in windows explorer. Right click it->Open With-
    >Choose Program...

    Now find your python.exe file (should be in c:\python24), select it,
    and tick the box that says "Always use the selected program"

    Iain
     
    Iain King, Jul 8, 2008
    #5
  6. On Jul 7, 4:56 pm, korean_dave <> wrote:
    > From command Prompt, i type in a script,  "tryme.py".
    >
    > This, instead, brings up PythonWin editor and Interactive Window.
    >
    > Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >
    > How do I make it so that the script runs?


    You need to add python.exe to your system's path. In Windows XP, you
    need right-click "My Computer", choose Properties, and then the
    Advanced tab. Click the Environment Variables button. Then go to the
    System Variables section and double-click the Path entry (you may have
    to scroll down to get to it).

    Notice that everything in this list is separated by semi-colons. You
    should be at the end of the list, so just put a semi-colon at the end
    and then type C:\Python24

    Then it should work. You'll probably need to restart your command line
    window though, as it doesn't always take affect on open windows.

    HTH

    -------------------
    Mike Driscoll

    Blog: http://blog.pythonlibrary.org
    Python Extension Building Network: http://www.pythonlibrary.org
     
    Mike Driscoll, Jul 8, 2008
    #6
  7. korean_dave

    norseman Guest

    OK- ;
    In Windows use the Window Explorer and go find a something.py.
    Right click on it and select Open With then Browse and go find your
    Python24\python.exe and select it. Then check the box that says "Always
    use this for..." and test it by closing/re-opening WinExplorer and left
    clicking (or double clicking if so set) and it should attempt to run.
    IF so then use the 'dos window' and try typing in just it's name.
    ie... tryme.py this should attempt to run also. If not, check the
    C:\autoexec.bat PATH line. It just might be that it has the unwanted
    Python editor's path there. If so, consider putting your python24 path
    BEFORE it. (Don't forget to re-boot after mods to autoexec.bat) If that
    isn't the problem you might consider a complete scrub, reformat and
    re-install of Windows and ALL your stuff. (Uggg!)

    Don't be surprised if at some point it may "reset itself" back to it's
    current bad behavior. The Python editor shouldn't unless it is
    re-installed for some reason.

    The use of the bat file ignores any 'self reset' nonsense by forcing the
    desired action(s) by keeping Windows from wandering about. During the
    development cycle a modified copy in the working directory can delete
    program created files before (re)running script. This keeps Microsoft
    from yelling it can't function because something is in it's way. And
    hardcoding the file under development, along with any needed tokens,
    simplifies the command line and the cycle.
    ( del any files created in this loop (one line each)
    ( drive:\path_to\python pgm.py token tokens.....
    ( don't remember if pause or whatever - but give time to inspect screen
    ( preferred_editor pgm.py

    if in t.bat then t<cr> tests it and returns you to edit.
    Saves lots of typos, lowers anxiety, speeds up cycle, increases
    confidence in progress.

    NOTE: I use Linux and I do have a typo in my original reply.
    USE %1 NOT %f in the .bat file. Sorry
    ^numeric one

    Steve

    =======================================================================

    David Eynon wrote:
    > When my anyname.py runs, instead of executing the script, it opens up
    > the file within the Pythonwin text editor.
    >

    =======================================================================
    > On Mon, Jul 7, 2008 at 9:00 PM, norseman <> wrote:
    >> korean_dave wrote:
    >>>> From command Prompt, i type in a script, "tryme.py".
    >>> This, instead, brings up PythonWin editor and Interactive Window.
    >>>
    >>> Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >>>
    >>> How do I make it so that the script runs?
    >>> --
    >>> http://mail.python.org/mailman/listinfo/python-list
    >>>

    >> ======================================
    >> I get tired of Microsoft jerking me around too. Rather than spend hours
    >> trying to undo somebody's reorganizing my system preferences I just ignore
    >> them completely.
    >>
    >> py tryme is how I do it.
    >>
    >> py.bat is a file placed in a directory listed in PATH in autoexec.bat. Edit
    >> autoexec.bat to include directory you put it in and reboot system or it
    >> won't find it. something like: PATH=.;c:\py-stuff;[anything already
    >> listed] Don't forget the semicolons.
    >>
    >> The . (period) up front means look here first. here being where ever you are
    >> when you issued the command. (The pRESENT wORKING dIRECTORY :) The
    >> c:\py-stuff (fix to suit yourself and make sure it exists) is where you can
    >> put your efforts to be called at your leisure. Your .py files you write and
    >> use. Even the py.bat can go there.
    >>
    >> (Short note: Microsoft usually does look in pwd first. But good form
    >> dictates being specific.)
    >>
    >> contents of py.bat:
    >> ========================
    >> rem name: py.bat
    >> @echo off
    >> c:\Python24\python %f.py make it fit your path
    >> rem end of file
    >> ========================
    >>
    >> This way - you get what you expect, when you expect it, & nothing else.
    >> Yeah - dumb, but it works! I have one similar for each of my compilers.
    >> They contain the whole command line switches stuff as well as things like
    >> remove old stuff before trying to over write with new since MS can be
    >> temperamental about that.
    >>
    >> Easiest way in the world to give it the finger and make it behave.
    >>
    >> Steve
    >>
    >>

    >
     
    norseman, Jul 8, 2008
    #7
  8. korean_dave

    Chris Hulan Guest

    On Jul 7, 5:56 pm, korean_dave <> wrote:
    > From command Prompt, i type in a script, "tryme.py".
    >
    > This, instead, brings up PythonWin editor and Interactive Window.
    >
    > Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >
    > How do I make it so that the script runs?


    sounds like you need to adjust the file association so .py files are
    associated with python.exe
     
    Chris Hulan, Jul 8, 2008
    #8
  9. korean_dave

    Matimus Guest

    On Jul 7, 2:56 pm, korean_dave <> wrote:
    > From command Prompt, i type in a script,  "tryme.py".
    >
    > This, instead, brings up PythonWin editor and Interactive Window.
    >
    > Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5)
    >
    > How do I make it so that the script runs?


    You can do this by editing the registry, but here is the general way
    to click through chaning file associations:

    Right click on any python file (*.py) and choose "Open With" from the
    context menu and select "Choose Program..." . From there select
    "Python" if it appears, or click "Browse" and browse to "C:
    \Python25\python.exe", or the appropriate location if you have it
    installed somewhere else.

    Make sure to check the box next to "Always use the selected program to
    open this kind of file."

    Click "Ok".

    Matt
     
    Matimus, Jul 8, 2008
    #9
  10. korean_dave

    Gerry Guest

    Gerry, Jul 9, 2008
    #10
    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. Stylus Studio
    Replies:
    0
    Views:
    770
    Stylus Studio
    Aug 3, 2004
  2. Replies:
    15
    Views:
    511
    Dave Thompson
    Aug 21, 2006
  3. pratap
    Replies:
    20
    Views:
    792
    Flash Gordon
    Mar 7, 2007
  4. Amit Gupta
    Replies:
    8
    Views:
    548
    BlueBird
    Apr 1, 2008
  5. davidj411
    Replies:
    0
    Views:
    584
    davidj411
    Jun 27, 2008
Loading...

Share This Page