The letter may be different, and there might be other things after it, so y ou might just
as easily see something like:
D:\Steve\Projects\Python>
depending on how y our computer has been set up and what else y ou hav e recently
done with it. Once y ou hav e started such a window, y ou are well on the way to running
Py thon programs.
Y ou need to realize that y our Py thon scripts hav e to be processed by another
program called the Py thon interpreter. The interpreter reads y our script, compiles it
into by tecodes, and then ex ecutes the by tecodes to run y our program. So, how do y ou
arrange for the interpreter to handle y our Py thon?
First, y ou need to make sure that y our command window recognises the word
py thon as an instruction to start the interpreter. If y ou hav e opened a command
window, y ou should try entering the command py thon and hitting return. Y ou should
then see something like:
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Y ou hav e started the interpreter in interactiv e mode. That means y ou can enter
Py thon statements or ex pressions interactiv ely and hav e them ex ecuted or ev aluated
while y ou wait. This is one of Py thons strongest features. Check it by entering a few
ex pressions of y our choice and seeing the results:
>>> print "Hello"
Hello
>>> "Hello" * 3
HelloHelloHello
Many people use the interactiv e mode as a conv enient y et highly programmable
calculator. When y ou want to end y our interactiv e Py thon session, hold the Ctrl key
down while y ou enter a Z, then hit the Enter key to get back to y our Windows
command prompt.
effbot.org/pyfaq/how-do-i-run-a-python-program-under-windows.htm
1/3
9/26/12
Y ou may also find that y ou hav e a Start-menu entry such as Start | Programs | Py thon
2.2 | Py thon (command line) that results in y ou seeing the >>> prompt in a new
window. If so, the window will disappear after y ou enter the Ctrl-Z character; Windows
is running a single py thon command in the window, and closes it when y ou
terminate the interpreter.
If the py thon command, instead of display ing the interpreter prompt >>>, giv es y ou a
message like:
'python' is not recognized as an internal or external command,
operable program or batch file.
or:
Bad command or filename
then y ou need to make sure that y our computer knows where to find the Py thon
interpreter. To do this y ou will hav e to modify a setting called PATH, which is a list of
directories where Windows will look for programs. Y ou should arrange for Py thons
installation directory to be added to the PATH of ev ery command window as it starts.
If y ou installed Py thon fairly recently then the command
dir C:\py*
will probably tell y ou where it is installed; the usual location is something like
C:\Py thon23. Otherwise y ou will be reduced to a search of y our whole disk use
Tools | Find or hit the Search button and look for py thon.ex e. Supposing y ou
discov er that Py thon is installed in the C:\Py thon23 directory (the default at the time
of writing), y ou should make sure that entering the command
c:\Python23\python
starts up the interpreter as abov e (and dont forget y oull need a CTRL-Z and an
Enter to get out of it). Once y ou hav e v erified the directory , y ou need to add it to the
start-up routines y our computer goes through. For older v ersions of Windows the
easiest way to do this is to edit the C:\AUTOEXEC.BAT file. Y ou would want to add a
line like the following to AUTOEXEC.BAT:
PATH C:\Python23;%PATH%
For Windows NT, 2000 and XP, y ou will need to add a string such as
;C:\Python23
to the current setting for the PATH env ironment v ariable, which y ou will find in the
properties window of My Computer under the Adv anced tab. Note that if y ou hav e
sufficient priv ilege y ou might get a choice of installing the settings either for the
Current User or for Sy stem. The latter is preferred if y ou want ev ery body to be able to
run Py thon on the machine.
If y ou arent confident doing any of these manipulations y ourself, ask for help! At this
stage y ou may want to reboot y our sy stem to make absolutely sure the new setting has
taken effect. Y ou probably wont need to reboot for Windows NT, XP or 2000. Y ou can
also av oid it in earlier v ersions by editing the file
C:\WINDOWS\COMMAND\CMDINIT.BAT instead of AUTOEXEC.BAT.
Y ou should now be able to start a new command window, enter py thon at the C:> (or
whatev er) prompt, and see the >>> prompt that indicates the Py thon interpreter is
reading interactiv e commands.
effbot.org/pyfaq/how-do-i-run-a-python-program-under-windows.htm
2/3
9/26/12
Because y ou added a file name to the command to start the interpreter, when it starts
up it reads the Py thon script in the named file, compiles it, ex ecutes it, and terminates,
so y ou see another C:\> prompt. Y ou might also hav e entered
C:\> python \Steve\Projects\Python\pytest.py
should giv e y ou a >>> prompt from the Py thon interpreter. Dont forget the
CTRL-Z and ENTER to terminate the interpreter (and, if y ou started the window
from the Start Menu, make the window disappear).
2. Once this works, y ou run programs with commands:
python {program-file}
3. When y ou know the commands to use y ou can build Windows shortcuts to run
the Py thon interpreter on any of y our scripts, naming particular working
directories, and adding them to y our menus. Take a look at
python --help
effbot.org/pyfaq/how-do-i-run-a-python-program-under-windows.htm
3/3