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 {{ book.pythonVersion }}.
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
(or another appropriate location) as the install location.
If you didn’t check the Add Python 3.5 PATH
option earlier, 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 (by checking the Add Python 3.5 Path
or Add Python to environment variables
options), then follow the steps in the next section (DOS Prompt
) to fix it. Otherwise, go to the Running Python prompt on Windows
section in this document.
NOTE: For people who already know programming, if you are familiar with Docker, check out Python in Docker and Docker 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
-> 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:
Control Panel
Advanced system settings
. Click that.Advanced
tab of the System Properties
dialog box is shown. Click the Environment Variables
button on the bottom right.System Variables
scroll down to Path and click the Edit
button.For Windows 7 and 8:
Properties
or click Start
and choose Control Panel
-> System and Security
-> System
. Click on Advanced system settings
on the left and then click on the Advanced
tab. At the bottom click on Environment Variables
and under System variables
, look for the PATH
variable, select and then press Edit
.;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.%SystemRoot%\system32;
It will now become %SystemRoot%\system32;C:\Python36
OK
and you are done. No restart is required, however you may have to close and reopen the command line.For Windows 10:
Windows Start Menu > Settings
> About
> System Info
(this is all the way over to the right) > Advanced System Settings
> Environment Variables
(this is towards the bottom) > (then highlight Path
variable and click Edit
) > New
> (type in whatever your python location is. For example, C:\Python35\
)
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
and ensure there are no errors.
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.
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
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.