Before installing, you must decide which version of Python you want. Both Python 2 and 3 are available from Python.org's official download page.
Visit https://www.python.org/downloads/ and download the latest version. The installation is just like any other Windows-based software.
CAUTION: When you are given the option of unchecking any "optional" components, don't uncheck any.
If you want to be able to use Python from the Windows command prompt (sometimes called the DOS prompt), then you need to set the PATH variable appropriately.
For Windows 2000, XP, 2003 , click on Control Panel -> System -> Advanced -> Environment Variables. Click on the variable named PATH in the System Variables section, then select Edit and add ;C:\Python35 (please verify that this folder exists, it will be different for newer versions of Python) to the end of what is already there. Of course, use the appropriate directory name.
For older versions of Windows, open the file C:\AUTOEXEC.BAT and add the line PATH=%PATH%;C:\Python35 and restart the system. For Windows NT, use the AUTOEXEC.NT file.
For Windows Vista:
- Click Start and choose
Control Panel - Click System, on the right you'll see "View basic information about your computer"
- On the left is a list of tasks, the last of which is
Advanced system settings. Click that. - The
Advancedtab of theSystem Propertiesdialog box is shown. Click theEnvironment Variablesbutton on the bottom right. - In the lower box titled
System Variablesscroll down to Path and click theEditbutton. - Change your path as need be.
- Restart your system. Vista didn't pick up the system path environment variable change until I restarted.
For Windows 7 and 8:
- Right click on Computer from your desktop and select
Propertiesor clickStartand chooseControl Panel->System and Security->System. Click onAdvanced system settingson the left and then click on theAdvancedtab. At the bottom click onEnvironment Variablesand underSystem variables, look for thePATHvariable, select and then pressEdit. - Go to the end of the line under Variable value and append
;C:\Python27(please verify that this folder exists, it will be different for newer versions of Python) to the end of what is already there. Of course, use the appropriate folder name. - If the value was
%SystemRoot%\system32;It will now become%SystemRoot%\system32;C:\Python35 - Click
OKand you are done. No restart is required, however you may have to close and reopen the command line.
For Windows users, you can run the interpreter in the command line if you have set the PATH variable appropriately.
To open the terminal in Windows, click the start button and click Run. In the dialog box, type cmd and press [enter] key.
Then, type python (for Python 2) or python3 (for Python 3) and ensure there are no errors.
For Mac OS X users, Python 2 is installed by default. You can use Homebrew to get Python 3: brew install python3.
To verify, open the terminal by pressing [Command + Space] keys (to open Spotlight search), type Terminal and press [enter] key. Now, run python (for Python 2) or python3 (for Python 3) and ensure there are no errors.
For GNU/Linux users, Python 2 comes installed by default on most distributions. You can use your distribution's package manager to install Python 3, e.g. on Debian & Ubuntu: sudo apt-get update && sudo apt-get install python3.
To verify, open the terminal by running the "Terminal" or "gnome-terminal" applications (or consult your distro's documentation on starting a terminal). Now, run python (for Python 2) or python3 (for Python 3) and ensure there are no errors.
You can see the version of Python on the screen by running:
$ python -V
Python 2.7.6
$ python3 -V
Python 3.5.1
NOTE: $ is the prompt of the shell. It will be different for you depending on the settings of the operating system on your computer, hence I will indicate the prompt by just the $ symbol.
CAUTION: Output may be different on your computer, depending on the version of Python software installed on your computer.
From now on, we will assume that you have Python installed on your system.
Next, we will write our first Python program.