When we refer to "Python 3" in this book, we will be referring to any version of Python equal to or greater than version Python 3.6.0.
Installation on Windows
Visit https://www.python.org/downloads/ and download the latest version. At the time of this writing, it was Python 3.5.1 The installation is just like any other Windows-based software.
Note that if your Windows version is pre-Vista, you should download Python 3.4 only as later versions require newer versions of Windows.
CAUTION: Make sure you check option
Add Python 3.5 to PATH.
To change install location, click on
Customize installation, then
Next and enter
C:\python35 as install location.
If not checked, check
Add Python to environment variables. This does the same thing as
Add Python 3.5 to PATH on the first install screen.
You can choose to install Launcher for all users or not, it does not matter much. Launcher is used to switch between different versions of Python installed.
If your path was not set correctly, then follow these steps to fix it. Otherwise, go to
Running Python prompt on Windows.
If you want to be able to use Python from the Windows command line i.e. the DOS prompt, then you need to set the PATH variable appropriately.
For Windows 2000, XP, 2003 , click on
Control Panel ->
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
For Windows Vista:
- Click Start and choose
- 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.
Advancedtab of the
System Propertiesdialog box is shown. Click the
Environment Variablesbutton on the bottom right.
- In the lower box titled
System Variablesscroll down to Path and click the
- 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
System and Security->
System. Click on
Advanced system settingson the left and then click on the
Advancedtab. At the bottom click on
Environment Variablesand under
System variables, look for the
PATHvariable, select and then press
- Go to the end of the line under Variable value and append
;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 folder name.
- If the value was
%SystemRoot%\system32;It will now become
OKand you are done. No restart is required, however you may have to close and reopen the command line.
Running Python prompt on Windows
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
python and ensure there are no errors.
Installation on Mac OS X
For Mac OS X users, use Homebrew:
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
python3 and ensure there are no errors.
Installation on GNU/Linux
For GNU/Linux users, 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 opening the
Terminal application or by pressing
Alt + F2 and entering
gnome-terminal. If that doesn't work, please refer the documentation of your particular GNU/Linux distribution. Now, run
python3 and ensure there are no errors.
You can see the version of Python on the screen by running:
$ python3 -V Python 3.6.0
$ 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
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.