Executing Python Scripts on Mac using Python Launcher

Discussion in 'Python' started by David Thomas, Jun 25, 2012.

  1. David Thomas

    David Thomas Guest

    Hello,
    This is my first post so go easy on me. I am just beginning to program using Python on Mac. When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same pieceof code and run it in windows it seems to execute as exactly intended.
    How can I make my python script to open up correctly using Python Launcher? I am running 10.7 on my Mac. I would upload a photo with the error I get but I can't seem to find the upload feature in this group.

    Thanks
     
    David Thomas, Jun 25, 2012
    #1
    1. Advertising

  2. On Mon, Jun 25, 2012 at 11:19 AM, David Thomas <> wrote:
    > Hello,
    > This is my first post so go easy on me.  I am just beginning to program using Python on Mac.  When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended.
    >  How can I make my python script to open up correctly using Python Launcher?  I am running 10.7 on my Mac.  I would upload a photo with the error I get but I can't seem to find the upload feature in this group.
    >
    > Thanks
    > --


    You can't find the upload feature because this isn't a Google Group.
    It's a Usenet newsgroup that Google Groups provides access to that's
    also available as a mailing list. If you want to provide an image, use
    an image host and link to the image.

    As to your question, I have a few questions of my own. What version of
    Python are you using? Is it the version included in Mac OS X,
    installed from a python.org binary, compiled by source, or installed
    through a package manager? What happens if you call the script from
    the command line instead of using the Launcher application?
     
    Benjamin Kaplan, Jun 25, 2012
    #2
    1. Advertising

  3. David Thomas

    David Thomas Guest

    I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error.Sorry I am new to Python and just want to know how I can open such a fileusing 10.7.

    Thanks

    http://www.freeimagehosting.net/ilbqt
    http://www.freeimagehosting.net/r5ars
    On Monday, June 25, 2012 8:49:07 PM UTC+1, Benjamin Kaplan wrote:
    > On Mon, Jun 25, 2012 at 11:19 AM, David Thomas <> wrote:
    > > Hello,
    > > This is my first post so go easy on me.  I am just beginning to program using Python on Mac.  When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended.
    > >  How can I make my python script to open up correctly using Python Launcher?  I am running 10.7 on my Mac.  I would upload a photo with the error I get but I can't seem to find the upload feature in this group.
    > >
    > > Thanks
    > > --

    >
    > You can't find the upload feature because this isn't a Google Group.
    > It's a Usenet newsgroup that Google Groups provides access to that's
    > also available as a mailing list. If you want to provide an image, use
    > an image host and link to the image.
    >
    > As to your question, I have a few questions of my own. What version of
    > Python are you using? Is it the version included in Mac OS X,
    > installed from a python.org binary, compiled by source, or installed
    > through a package manager? What happens if you call the script from
    > the command line instead of using the Launcher application?
     
    David Thomas, Jun 26, 2012
    #3
  4. David Thomas

    David Thomas Guest

    I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error.Sorry I am new to Python and just want to know how I can open such a fileusing 10.7.

    Thanks

    http://www.freeimagehosting.net/ilbqt
    http://www.freeimagehosting.net/r5ars
    On Monday, June 25, 2012 8:49:07 PM UTC+1, Benjamin Kaplan wrote:
    > On Mon, Jun 25, 2012 at 11:19 AM, David Thomas <> wrote:
    > > Hello,
    > > This is my first post so go easy on me.  I am just beginning to program using Python on Mac.  When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended.
    > >  How can I make my python script to open up correctly using Python Launcher?  I am running 10.7 on my Mac.  I would upload a photo with the error I get but I can't seem to find the upload feature in this group.
    > >
    > > Thanks
    > > --

    >
    > You can't find the upload feature because this isn't a Google Group.
    > It's a Usenet newsgroup that Google Groups provides access to that's
    > also available as a mailing list. If you want to provide an image, use
    > an image host and link to the image.
    >
    > As to your question, I have a few questions of my own. What version of
    > Python are you using? Is it the version included in Mac OS X,
    > installed from a python.org binary, compiled by source, or installed
    > through a package manager? What happens if you call the script from
    > the command line instead of using the Launcher application?
     
    David Thomas, Jun 26, 2012
    #4
  5. David Thomas

    Dave Angel Guest

    On 06/26/2012 01:19 PM, David Thomas wrote:
    > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    >
    > Thanks


    Assuming python is on your PATH within that terminal, you'd normally do
    something like:

    cd /fullpathtoscript (the location of your script)
    python myscript.py (or whatever your script is called)


    If that doesn't work for you, please be specific about what happens.
    Best way to do that is to copy/paste the text (showing in terminal)
    into your reply here.

    Also, please don't top-post. Put your new text AFTER the part you've
    quoted from earlier messages.

    --

    DaveA
     
    Dave Angel, Jun 26, 2012
    #5
  6. David Thomas

    David Thomas Guest

    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA


    Hi

    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA
     
    David Thomas, Jun 26, 2012
    #6
  7. David Thomas

    David Thomas Guest

    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA


    Hi

    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA




    On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    > On 06/26/2012 01:19 PM, David Thomas wrote:
    > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7.
    > >
    > > Thanks

    >
    > Assuming python is on your PATH within that terminal, you'd normally do
    > something like:
    >
    > cd /fullpathtoscript (the location of your script)
    > python myscript.py (or whatever your script is called)
    >
    >
    > If that doesn't work for you, please be specific about what happens.
    > Best way to do that is to copy/paste the text (showing in terminal)
    > into your reply here.
    >
    > Also, please don't top-post. Put your new text AFTER the part you've
    > quoted from earlier messages.
    >
    > --
    >
    > DaveA
     
    David Thomas, Jun 26, 2012
    #7
  8. David Thomas

    David Thomas Guest

    On Monday, June 25, 2012 7:19:54 PM UTC+1, David Thomas wrote:
    > Hello,
    > This is my first post so go easy on me. I am just beginning to program using Python on Mac. When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended.
    > How can I make my python script to open up correctly using Python Launcher? I am running 10.7 on my Mac. I would upload a photo with the error I get but I can't seem to find the upload feature in this group.
    >
    > Thanks


    Thank you for the fast response. How can I tell if Python is in the same path as Terminal? Is this located in the /usr folder?

    Thanks again
     
    David Thomas, Jun 26, 2012
    #8
  9. David Thomas

    Dave Angel Guest

    (You forgot to include the list on this message, but I'm including them
    in my reply)

    On 06/26/2012 02:07 PM, David Thomas wrote:
    >
    >
    > On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote:
    >>
    >> On 06/26/2012 01:19 PM, David Thomas wrote:
    >>> I have installed Python 2.7.3 from Python.org also in Terminal it states

    >> that I have 2.7.3.
    >>> How can I execute the script from Terminal? I've tried typing python

    >> into the window and then dragging the file to terminal but I get a syntax
    >> error. Sorry I am new to Python and just want to know how I can open such
    >> a file using 10.7.
    >>>
    >>>

    >> <SNIP>
    >>

    > Thanks for the fast response how can I find out if Python is on the same
    > path as Terminal?
    >
    > Is this located in the /usr Folder?
    >
    > Thanks
    >


    Looks like you're new to Unix as well. (the following applies to Unix,
    Linux, OS/X, and with modifications, to Windows)

    Terminal is a program.

    PATH is an environment variable. You normally set it globally, but it's
    sometimes modified by various scripts. To see what it is in a given
    Terminal session, simply issue the command:

    echo $PATH

    To see all your environment variables, use

    printenv

    Anyway, PATH is a list of directories that bash (or whatever shell
    you're using) will search. If you can run python with the simple command:

    python

    then it IS on your PATH. That means that you do NOT want to cd to the
    directory of python, but to the directory where your script is located.

    cd /fullpathtoscript (the location of your script)
    python myscript.py (or whatever your script is called)


    --

    DaveA
     
    Dave Angel, Jun 26, 2012
    #9
  10. On Tue, Jun 26, 2012 at 10:19 AM, David Thomas <> wrote:
    > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3.
    > How can I execute the script from Terminal?  I've tried typing python into the window and then dragging the file to terminal but I get a syntaxerror.  Sorry I am new to Python and just want to know how I can opensuch a file using 10.7.
    >
    > Thanks
    >
    > http://www.freeimagehosting.net/ilbqt
    > http://www.freeimagehosting.net/r5ars


    My guess would be that you're getting a SyntaxError when you run it
    through the Launcher too. WIthout seeing the script, I don't know why
    that would is.

    I can tell you one thing you're doing wrong. Never, ever, use input()
    in Python 2. If you do, all someone has to do is type in
    __import__('os').remove(__file__) and stuff starts getting deleted.
    "input" interprets what it reads in. Use raw_input() instead, which
    always returns a string.
     
    Benjamin Kaplan, Jun 26, 2012
    #10
  11. David Thomas

    Hans Mulder Guest

    On 26/06/12 20:11:51, David Thomas wrote:
    > On Monday, June 25, 2012 7:19:54 PM UTC+1, David Thomas wrote:
    >> Hello,
    >> This is my first post so go easy on me. I am just beginning to program using Python on Mac. When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended.
    >> How can I make my python script to open up correctly using Python Launcher? I am running 10.7 on my Mac. I would upload a photo with the error I get but I can't seem to find the upload feature in this group.
    >>
    >> Thanks

    >
    > Thank you for the fast response. How can I tell if Python is in the same path as Terminal?


    It isn't. Terminal is an application and is located in
    /Applications/Utilities . Python is an executable, and is
    typically located in a "bin" directory. To find out where
    it is, type

    type python

    at the shell prompt (that's the first prompt you get if you
    open a Terminal window).

    Possible answers include:

    /usr/bin/python
    This is the Python shipped by Apple

    /Library/Frameworks/Python.framework/Versions/2.7/bin/python
    This is a Python from python.org

    /opt/local/bin/python
    This is a Python from macports

    > Is this located in the /usr folder?


    If you mean /usr/bin, that's the Python that came with your Mac.
    If you haven't installed any other Pythons, then yes, you must
    be using that one.


    Hope this helps,

    -- HansM
     
    Hans Mulder, Jun 26, 2012
    #11
  12. On Tue, 26 Jun 2012 10:19:45 -0700 (PDT), David Thomas
    <> declaimed the following in gmane.comp.python.general:


    > http://www.freeimagehosting.net/ilbqt


    That's an interesting configuration...

    "pythonw.exe" is a version of the Python interpreter designed to NOT
    OPEN a console -- so you've got a configuration saying "open a console
    to run a no-console interpreter".

    Normally pythonw.exe is used with scripts having .pyw extension;
    these are scripts that use tkinter, wxPython, or other GUI system to
    create a graphical environment and don't want a console (terminal)
    window cluttering the screen when they don't use text I/O.

    Console based programs (.py) should be run using python.exe; adjust
    your settings.

    > http://www.freeimagehosting.net/r5ars


    And this is to be expected... In Python 2.x, "input()" attempts to
    evaluate the input data, and you didn't supply anything -- hence EOF.
    For your usage, you want "raw_input()", which just grabs the next line
    of text and returns it as a string.


    As for how to run if you've opened a console (shell [bash]) window,
    the way to run a script is to type

    python <path/name/to/your/script>.py <any command line arguments>


    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jun 26, 2012
    #12
  13. David Thomas

    Hans Mulder Guest

    On 26/06/12 21:51:41, Dennis Lee Bieber wrote:
    > On Tue, 26 Jun 2012 10:19:45 -0700 (PDT), David Thomas
    > <> declaimed the following in gmane.comp.python.general:
    >
    >
    >> http://www.freeimagehosting.net/ilbqt

    >
    > That's an interesting configuration...
    >
    > "pythonw.exe" is a version of the Python interpreter designed to NOT
    > OPEN a console -- so you've got a configuration saying "open a console
    > to run a no-console interpreter".


    That's on Windows; on the Mac python and pythonw are identical.
    In fact, they're hard links to the same file.

    > Normally pythonw.exe is used with scripts having .pyw extension;
    > these are scripts that use tkinter, wxPython, or other GUI system to
    > create a graphical environment and don't want a console (terminal)
    > window cluttering the screen when they don't use text I/O.
    >
    > Console based programs (.py) should be run using python.exe; adjust
    > your settings.


    That shouldn't matter on a Mac.

    You may want to check "allow #! to override", though.

    I mean, if there is a #! in a file pointing to a specific version of
    python, then it's probably there for a reason. For example, the script
    might use a third party module installed only in that Python install.

    >> http://www.freeimagehosting.net/r5ars

    >
    > And this is to be expected... In Python 2.x, "input()" attempts to
    > evaluate the input data, and you didn't supply anything -- hence EOF.
    > For your usage, you want "raw_input()", which just grabs the next line
    > of text and returns it as a string.


    What he says.

    > As for how to run if you've opened a console (shell [bash]) window,
    > the way to run a script is to type
    >
    > python <path/name/to/your/script>.py <any command line arguments>



    Hope this helps,

    -- HansM
     
    Hans Mulder, Jun 26, 2012
    #13
  14. David Thomas

    Hans Mulder Guest

    On 26/06/12 22:41:59, Dave Angel wrote:
    > On 06/26/2012 03:16 PM, Hans Mulder wrote:
    >> <SNIP>
    >>
    >> Python is an executable, and is
    >> typically located in a "bin" directory. To find out where
    >> it is, type
    >>
    >> type python
    >>
    >> at the shell prompt (that's the first prompt you get if you
    >> open a Terminal window).
    >>
    >>

    >
    > That's a typo. You presumably meant:
    >
    > which python
    >


    No, I meant:

    $ type python
    python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python

    'type' is a bash builtin that tells you how bash would interpret
    a command. 'which' is a separate program, which tells you how
    csh would interpret a command. For a 'bash' user, 'type' is more
    accurate than 'which'. For example, 'type' recognizes 'bash'
    builtins.

    -- HansM
     
    Hans Mulder, Jun 26, 2012
    #14
  15. On Tue, 26 Jun 2012 22:12:54 +0200, Hans Mulder <>
    declaimed the following in gmane.comp.python.general:

    > On 26/06/12 21:51:41, Dennis Lee Bieber wrote:
    > > On Tue, 26 Jun 2012 10:19:45 -0700 (PDT), David Thomas
    > > <> declaimed the following in gmane.comp.python.general:
    > >
    > >
    > >> http://www.freeimagehosting.net/ilbqt

    > >
    > > That's an interesting configuration...
    > >
    > > "pythonw.exe" is a version of the Python interpreter designed to NOT
    > > OPEN a console -- so you've got a configuration saying "open a console
    > > to run a no-console interpreter".

    >
    > That's on Windows; on the Mac python and pythonw are identical.
    > In fact, they're hard links to the same file.


    Okay, but...

    It may still be cleaner (to non-Mac users) if the execution
    preferences still kept the "use terminal" to the python.exe, and left
    "pythonw.exe" to "no terminal" applications <G>

    Even if the same executable is used in the end...

    >
    > You may want to check "allow #! to override", though.
    >
    > I mean, if there is a #! in a file pointing to a specific version of
    > python, then it's probably there for a reason. For example, the script
    > might use a third party module installed only in that Python install.
    >

    While I knew what that option meant, I didn't mention it myself as
    the OP probably (based on the nature of the questions) wouldn't
    understand the meaning... (And, on Windows at least, #! lines don't do
    anything <G>)

    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jun 26, 2012
    #15
  16. On 26/06/2012 23:35, Dennis Lee Bieber wrote:
    >
    > (And, on Windows at least, #! lines don't do
    > anything<G>)
    >


    New for Python 3.3 http://www.python.org/dev/peps/pep-0397/

    --
    Cheers.

    Mark Lawrence.
     
    Mark Lawrence, Jun 27, 2012
    #16
  17. David Thomas

    Dave Angel Guest

    On 06/26/2012 05:48 PM, Hans Mulder wrote:
    > On 26/06/12 22:41:59, Dave Angel wrote:
    > <SNIP>


    > No, I meant: $ type python python is
    > /Library/Frameworks/Python.framework/Versions/2.7/bin/python 'type' is
    > a bash builtin that tells you how bash would interpret a command.
    > 'which' is a separate program, which tells you how csh would interpret
    > a command. For a 'bash' user, 'type' is more accurate than 'which'.
    > For example, 'type' recognizes 'bash' builtins. -- HansM


    Thanks for the information. "which" has worked on every unix-like system
    I've used for 25 years. I never knew that bash had its own extension.


    --

    DaveA
     
    Dave Angel, Jun 27, 2012
    #17
  18. David Thomas

    David Thomas Guest

    On Tuesday, June 26, 2012 10:48:22 PM UTC+1, Hans Mulder wrote:
    > On 26/06/12 22:41:59, Dave Angel wrote:
    > > On 06/26/2012 03:16 PM, Hans Mulder wrote:
    > >> <SNIP>
    > >>
    > >> Python is an executable, and is
    > >> typically located in a "bin" directory. To find out where
    > >> it is, type
    > >>
    > >> type python
    > >>
    > >> at the shell prompt (that's the first prompt you get if you
    > >> open a Terminal window).
    > >>
    > >>

    > >
    > > That's a typo. You presumably meant:
    > >
    > > which python
    > >

    >
    > No, I meant:
    >
    > $ type python
    > python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
    >
    > 'type' is a bash builtin that tells you how bash would interpret
    > a command. 'which' is a separate program, which tells you how
    > csh would interpret a command. For a 'bash' user, 'type' is more
    > accurate than 'which'. For example, 'type' recognizes 'bash'
    > builtins.
    >
    > -- HansM


    I have the following:

    Is this why I keep getting an error using launcher? Also to open the script in terminal do I need to put the following at the beginning of my script: #!/bin/python

    On python.org it states to To run your script from the Terminal window you must make sure that /usr/local/bin is in your shell search path.

    How can I make sure that the Python I have installed on my Mac is in my shell search path.

    http://www.freeimagehosting.net/saskk

    Thanks again and I am sorry for all the questions, I am just getting started on Python
     
    David Thomas, Jun 27, 2012
    #18
  19. David Thomas

    Hans Mulder Guest

    On 27/06/12 19:05:44, David Thomas wrote:
    > Is this why I keep getting an error using launcher?


    No.

    Yesterday your problem was that you tried this:

    input("\n\nPress the enter key to exit")

    That works fine in Pyhton3, but you are using python2
    and in python2, the you must do this instead:

    raw_input("\n\nPress the enter key to exit")

    If you still get that error, you can either use "raw_input()"
    or switch to Python3, where "input" would be correct.

    If you're learning Python from a tutorial, you should
    carefully read the first section of the tutorial, where
    they mention whether the explains pyhton2 or python3,
    and use a matching Python (or a matching tutorial).

    If the tutorial doesn't say for which version it is,
    then it's for pyhton2 (and several years old).

    > Also to open the script in terminal do I need to put
    > the following at the beginning of my script:
    >
    > #!/bin/python


    No, that doesn't help.

    There are at least three pythons on your system, but
    there isn't one in /bin. There are basically two ways
    to run a python script in terminal:

    Method 1: type the word "python", followed by a space and
    the full path to your script, enclosed in quotes, e.g.

    python '/Users/dthomaw86/Documents/Python Documents/game_over_enter_key.py'

    The quotes are necessary, because you have a space
    character in the path.

    Method 2:
    Step 1: put valid a '#!' line at the top of the script,
    for example:

    #!/ust/local/bin/python

    Step 2: in Terminal, go to the folder where the script is:

    cd '/Users/dthomaw86/Documents/Python Documents'

    Step 3: make the script "executable"

    chmod +x game_over_enter_key.py

    Step 4: you can now run the script with:

    ./game_over_enter_key.py

    If you want to run the script again, you only need to repeat
    step 4. Or use the "up arrow" key in Terminal.

    I think you should pick one method and stick with it, until
    you get the hang of Terminal.

    > On python.org it states to To run your script from the Terminal
    > window you must make sure that /usr/local/bin is in your shell
    > search path.


    The installer for Mac from python.org has installed python2.7
    in /Libary/Frameworks/Python.frameworks/Versions/2.7/bin and
    added that directory to you shell search path.

    > How can I make sure that the Python I have installed on my Mac
    > is in my shell search path.
    >
    > http://www.freeimagehosting.net/saskk


    If you look at the screen shot, you'll see that the shell
    has found python in
    /Libary/Frameworks/Python.frameworks/Versions/2.7/bin

    Incidentally, you don't have to upload screenshots from
    Termimal. You can you just select text in Terminal and
    use cmd-C to copy it to the clipboard, and then cmd-V to
    paste it to this forum. This is a text-only forum, but
    text from Terminal _is_ text, so that's allowed.

    For example:

    HansM 4$ cat game_over_enter_key.py
    raw_input("\n\nPress the enter key to exit")
    HansM 5$ python game_over_enter_key.py


    Press the enter key to exit
    HansM 6$

    > Thanks again and I am sorry for all the questions,
    > I am just getting started on Python


    That's all right: most people run into this sort of issues
    when they try their first script. There are usually several
    ways to do things, and that leads to you getting conflicting
    advice.


    Hope this helps,

    -- HansM
     
    Hans Mulder, Jun 27, 2012
    #19
  20. David Thomas

    David Thomas Guest

    Thank you ever so much raw_input works fine. Do you think I should stick with Python 2 before I go to 3?
    I have a text book which is using 3 but I've been using an online tutorial which has been helping me lots, which uses version 2.
    I found by just typing python then having a space and dragging the file from finder into terminal works.
     
    David Thomas, Jun 27, 2012
    #20
    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. Telicalbook
    Replies:
    3
    Views:
    4,861
    Federico
    Feb 1, 2005
  2. Replies:
    1
    Views:
    1,253
    ellios
    Oct 7, 2006
  3. =?iso-8859-1?B?QW5kcuk=?=

    Python launcher not working on Mac after Leopard upgrade?

    =?iso-8859-1?B?QW5kcuk=?=, Nov 3, 2007, in forum: Python
    Replies:
    3
    Views:
    469
    Cliff Harris
    Nov 6, 2007
  4. davidj411
    Replies:
    0
    Views:
    583
    davidj411
    Jun 27, 2008
  5. Thomas Heller
    Replies:
    7
    Views:
    190
    Andreas Röhler
    Feb 1, 2013
Loading...

Share This Page