Downloading and Installing Python
You can download Python for Windows, OS X, and Ubuntu for free from http://python.org/downloads/. If you download the latest version from the website’s download page, all of the programs in this book should work.
WARNINGBe sure to download a version of Python 3 (such as 3.4.0). The programs in this book are written to run on Python 3 and may not run correctly, if at all, on Python 2.
You’ll find Python installers for 64-bit and 32-bit computers for each operating system on the download page, so first figure out which installer you need. If you bought your computer in 2007 or later, it is most likely a 64-bit system. Otherwise, you have a 32-bit version, but here’s how to find out for sure:
- On Windows, select Start▸Control Panel▸System and check whether System Type says 64-bit or 32-bit.
- On OS X, go the Apple menu, select About This Mac▸More Info ▸ System Report▸Hardware, and then look at the Processor Name field. If it says Intel Core Solo or Intel Core Duo, you have a 32-bit machine. If it says anything else (including Intel Core 2 Duo), you have a 64-bit machine.
- On Ubuntu Linux, open a Terminal and run the command uname -m. A response of i686 means 32-bit, and x86_64 means 64-bit.
On Windows, download the Python installer (the filename will end with .msi) and double-click it. Follow the instructions the installer displays on the screen to install Python, as listed here:
- Select Install for All Users and then click Next.
- Install to the C:\Python34 folder by clicking Next.
- Click Next again to skip the Customize Python section.
On Mac OS X, download the .dmg file that’s right for your version of OS X and double-click it. Follow the instructions the installer displays on the screen to install Python, as listed here:
- When the DMG package opens in a new window, double-click the Python.mpkg file. You may have to enter the administrator password.
- Click Continue through the Welcome section and click Agree to accept the license.
- Select HD Macintosh (or whatever name your hard drive has) and click Install.
If you’re running Ubuntu, you can install Python from the Terminal by following these steps:
- Open the Terminal window.
- Enter sudo apt-get install python3.
- Enter sudo apt-get install idle3.
- Enter sudo apt-get install python3-pip.
Starting IDLE
While the Python interpreter is the software that runs your Python programs, the interactive development environment (IDLE) software is where you’ll enter your programs, much like a word processor. Let’s start IDLE now.
- On Windows 7 or newer, click the Start icon in the lower-left corner of your screen, enter IDLE in the search box, and select IDLE (Python GUI).
- On Windows XP, click the Start button and then select Programs ▸ Python 3.4▸IDLE (Python GUI).
- On Mac OS X, open the Finder window, click Applications, click Python 3.4, and then click the IDLE icon.
- On Ubuntu, select Applications▸Accessories▸Terminal and then enter idle3. (You may also be able to click Applications at the top of the screen, select Programming, and then click IDLE 3.)
The Interactive Shell
No matter which operating system you’re running, the IDLE window that first appears should be mostly blank except for text that looks something like this:
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32Type "copyright", "credits" or "license()" for more information. >>>
This window is called the interactive shell. A shell is a program that lets you type instructions into the computer, much like the Terminal or Command Prompt on OS X and Windows, respectively. Python’s interactive shell lets you enter instructions for the Python interpreter software to run. The computer reads the instructions you enter and runs them immediately.
For example, enter the following into the interactive shell next to the >>> prompt:
>>> print('Hello world!')
After you type that line and press ENTER, the interactive shell should display this in response:
>>> print('Hello world!') Hello world!