[Tutor] Running Existing Python
ALAN GAULD
alan.gauld at btinternet.com
Sat Feb 26 10:29:26 CET 2011
The error says it can't find the file hello.py.
That means its probably in some other folder
or you need to specify the full or relative path to the file
This is a MacOS issue not Python, its how your MacOS
shell is searching for the file.
If it is in the same folder try explicitly telling MacOS:
$ python ./hello.py
Or if it is somewhere else either cd to that folder
or type the path:
$ python /the/full/path/to/the/dfile/hello.py
There are some environment variables you can
set in your login script which will help MacOS
find the files but they depend on which shell
Terminal is running, tcsh or bash are the usual
options.
Finally there is a trick you can use on the hello.py
file that means you can launch the .py file directly
from Finder. It's called the shebang trick by Unix
folks.
Basically you add a line like
#! /usr/env/python
To the very top of the file. MacOS will then use that
command to execute the script. If usr/env doesn't
work type
$ which python
and copy the output instead of /usr/env
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
----- Original Message ----
> From: Justin Bonnell <jwbonnell5 at gmail.com>
> To: Alan Gauld <alan.gauld at btinternet.com>
> Cc: tutor at python.org
> Sent: Saturday, 26 February, 2011 6:49:37
> Subject: Re: [Tutor] Running Existing Python
>
> Okay. When I try to run the script from the terminal, it still doesn't work.
>Here is a screenshot.
>
>
> What am I doing wrong?
>
>
> On Feb 25, 2011, at 6:46 PM, Alan Gauld wrote:
>
> >
> > "Justin Bonnell" <jwbonnell5 at gmail.com> wrote
> >
> >> Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple Inc.
>build 5664)] on darwin
> >> Type "copyright", "credits" or "license()" for more information.
> >
> > The >>> prompt means you are already inside Python.
> > You can type Python commands at the >>> prompt, things like
> >
> >>>> print "Hello"
> >
> > But you cannot ruin a program from inside the >>> prompt (well, you can, but
>its more complicated than sane people want to bother with! :-)
> >
> > You run a Python script from the OS Terminal prompt:
> >
> > $ python hello.py
> >
> >> Shouldn't I be able to run hello.py from the IDLE interpreter?
> >
> > You can't run it from the >>> prompt in IDLE but....
> > What you can do is open the file for editing and then run that file using
>the menu commands, then the output will show up in the interpreter window.
> >
> I get how to do this now^^
> > HTH,
> >
> > --
> > Alan Gauld
> > Author of the Learn to Program web site
> > http://www.alan-g.me.uk/
> >
> >
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list