Note: If you have a Python 2.x that is 2.6 or later - you can use the Python you already have on your system.
Please download and install Python 2.7.5 from:
Download and install the file python-2.7.5.msi - when the install process asks you which directory to use - make sure to keep the default directory of C:\Python27\ (or C:\Python26\). If you are not sure if your Windows is 64-bit - install the 32-bit version of Python.
Note: Make sure that you install the latest version of Python 2.x - do not install Python 3.x. There are signficant differences between Python 2 and Python 3 and this book/site is still Python 2.Pre-Requisite: NotePad++
Please download and install NotePad++ from this site. Look for the ".exe" installer file to download and then run to install NotePad++.
Important: Before you create your first program, you need to make one small change in the Preferences for NotePad++. This will save you lots of "Python indent errors" anguish later. Under Settings -> Preferences -> Language Menu/Tab Settings or Settings -> Preferences -> Edit Components tick the check box for "Replace by space" leaving the value at "4" and press the "Close" button (Screenshot).
Note: We have a screen cast for the use of NotePad++. You can either view this on YouTube or you can download the high-quality QuickTime version of the screen cast. You will need Apple QuickTime installed to view this video.
Start NotePad++ from either a Desktop icon or from the Start Programs menu and enter your first Python program into NotePad++:
print "Hello World"
Save your program as firstprog.py onto your Desktop. You will notice that after you save the file, NotePad++ will color your code based on the Python syntax rules. Syntax coloring is a very helpful feature as it gives you visual feedback about your program and can help you track down syntax errors more easily. NotePad++ only knows that your file is a Python file after you save it with a ".py" suffix.
Press Start (the round Window icon in the lower right) and in the space called Start Search type in the word command - Windows will find the "Command Prompt" - select and launch the Command Prompt.
To start the command line interface to Windows XP, do Start -> Run -> cmd -> OK
When the command line starts up, you are in your "home" directory. Your home directory is different for each of the operating systems. In each of these examples, your logged in account should be used instead of csev.
Windows XP: C:\Documents and Settings\csev Windows Vista: C:\Users\csev Windows 7: C:\Users\csevThe command line prompt usually includes some clue as to where you are in the folder structure on your hard drive.
If you want to really figure out where you are, use the cd command with no parameters
C:\Documents and Settings\csev> cd C:\Documents and Settings\csev
Where can you go?
Generally the first thing you want to do when you open a command line interface is to navigate to the right folder. Say you wanted to run a file from your desktop. The command is cd Desktop to get into the folder that is your Desktop. You can use the dir command to see which files are in the current directory and the cd .. command to go "up" a directory
Nifty Trick: On the cd command, you can partially type a folder name like Desktop and then press the TAB key and the system will auto-complete the folder name if you have typed enough that the system can accurately guess what you mean to type.
If you get Lost...
If you can't figure out what folder you are in and/or cannot figure out how to get to the folder you want to get to - simply close and re-open the Command Line / Terminal window. You will be back to your "home" directory - so you can start from a known location.
Some Cool Hints on the Windows Command Line Interface
If you click on the little icon in the upper-left of the command prompt window and select Preferences - you can set many things about the command line - probably the most important is to set the Command History Buffer Size to be 999.
To run your program in the command line you type at the command line prompt. Windows knows that files wthat end with a ".py" suffix are Python programs.
firstprog.pyWhere firstprog.py is the name of the file containing your Python program. Make sure to use the cd command to be in the correct directory that contains your program file(s).
You can run your program over and over again in the command window. Hint: You can use the up-arrow key to scroll back through previous commands and re-execute them by pressing enter. This allows you to quickly edit and rerun your program to make and test changes.
Also, if you know how to update the PATH information in your Control Panel, you can add the C:\Python27 folder to your path and then you should be able to start Python form the command line by by simply typing "python". While setting the PATH information is not hard, it is a little different on each version of the Windows operating systems. You might want to get someone to help you set your PATH information so you don't have to type the full path each time you want to start Python.