Let There Be Python: Downloading and Installing

Before we can use Python, it must be installed on our computer. This chapter will cover a number of installation scenarios.

You’ll need to have access to a reasonably modern computer. This can be either a Macintosh with MacOS X, a Windows machine with Windows XP or higher, or any of the wide variety of GNU/Linux or UNIX machines. The computer doesn’t need to be spectacular or huge, just a machine that works reliably.

You’ll also need a few basic computer skills; if you’re new to computing, you might need a couple of “For Dummy’s” books to fill in your background. Since you’re going to download and install software, you’ll need access to the Internet, plus authority to install software on your computer. In an office or academic environment, you might not have permission to install new software; in this case, you’ll need to work through the organization that provides your computer to do the installation for you.

This chapter has a number of sections, but you’ll only really need to read a little bit of this chapter, depending on your operating system.

  • Windows. You need to work through Windows Installation, where we describe downloading Python 2.6 (or newer) and installing it.
  • Mac OS. Python is included. You may want to upgrade your Python to the latest and greatest. We’ll look at a Mac OS upgrade in Macintosh Installation.
  • GNU/Linux. Generally, Python is included. Often, the upgrades are automatically done. We’ll look at the common variations on the GNU/Linux installation in GNU/Linux and UNIX Overview. If you have YUM, for example, see YUM Installation.

Once we have Python installed, we can move on to interact with the Python program in the next chapter.

Windows Installation

The Windows installation of Python has three broad steps.

  1. Pre-installation: make backups and download the installation kit.
  2. Installation: install Python.
  3. Post-installation: check to be sure everything worked.

We’ll go through each of these in detail.

Windows Pre-Installation

Backup. Before installing software, back up your computer.

Download. After making a backup, go to the http://www.python.org web site and look for the Download area. In here, you’re looking for the pre-built Windows installer. This book will emphasize Python 2.6. In that case, the kit is python-2.6.6.msi. When you click on the filename, your browser should start downloading the file. Save it in your downloads folder.

A newer Python 2 (e.g. 2.7) is also a candidate for a download. Python 3, however, has enough differences that it will be confusing; do not download Python 3.

Prepare. If you have anti-virus software [you do, don’t you?] you may need to disable this until you are done installing Python.

At this point, you have everything you need to install Python:

  • A backup
  • The Python installer

Windows Installation

Double-click the Python installer (python-2.6.6.msi).

You should get a “Security Warning” asking if you want to run this file. The answer is to click Run.

First, you’ll be asked if you want to install for all users or just yourself. You require administrator privileges to install for all users. If you’re using a corporate PC, for example, you might not have administrator privileges. If you have the privileges, then install for all users. Otherwise, install for yourself. Click Next to continue.

The next step is to select a destination directory. The default destination should be C:\Python26. Note that Python does not expect to live in the C:\My Programs folder. There’s a subtle problem with the My Programs folder: it has a space in the middle of the name, something that is atypical for operating systems other than Windows. This space is sometimes unexpected by Python programs, and can cause no end of obscure problems. Consequently, Python folks prefer to put Python into C:\Python26 on Windows machines. Click Next to continue.

The next step is to customize list of components to install. You have a list of five components. You have no reason to change these.

  • Register Extensions. You want this.
  • Tcl/Tk (Tkinter, IDLE, pydoc). You want this, so that you can use IDLE to build programs.
  • Documentation (Python HTML Help file). This is some reference material that you’ll probably want to have.
  • Utility scripts (Tools/). We won’t be making any use of this; it’s simplest if you install it.
  • Python test suite (Lib/test/). We won’t make any use of this, either. It won’t hurt anything if you install it.

Click Next to continue.

The installer puts files in the selected places. This takes less than a minute.

Click Finish; you have just installed Python on your computer.

Tip

Debugging Windows Installation

The only problem you are likely to encounter doing a Windows installation is a lack of administrative privileges on your computer. In this case, you will need help from your support department to either do the installation for you, or give you administrative privileges.

Windows Post-Installation

In your Start... menu, under All Programs, you will now have a Python 2.6 group that lists five things:

  • IDLE (Python GUI)
  • Module Docs
  • Python (command line)
  • Python Manuals
  • Uninstall Python

GUI is the Graphic User Interface . We’ll turn to IDLE in IDLE Time : Using Tools To Be More Productive.

Important

Testing

If you select the Python (command line) menu item, you’ll see the Python (command line) window. This will contain something like the following.

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

If you hit Ctrl-Z and then Enter, Python will exit. The basic Python program works. You can skip to the next chapter to start using Python.

If you select the Python Manuals menu item, this will open a Microsoft Help reader that will show the complete Python documentation library.

Macintosh Installation

Python is part of the MacOS environment.

This from-the-factory installation includes a copy of IDLE, but it isn’t always obvious where it is located on your Macintosh. You can skip down to Adding IDLE Without An Install on Mac OS X for information on making use of IDLE without doing an install.

It’s easier to upgrade your copy of Python to 2.6.6. This will make IDLE available as a first-class icon in your Applications folder.

In order to install software in the Macintosh OS, you must know the administrator, or “owner” password. If you are the person who installed or initially setup the computer, you had to pick an owner password during the installation. If someone else did the installation, you’ll need to get the password from them.

The Mac OS installation of Python has three broad steps.

  1. Pre-installation: make backups and download the installation kit.
  2. Installation: install Python.
  3. Post-installation: check to be sure everything worked.

We’ll go through each of these in detail.

Macintosh Pre-Installation

Backup. Before installing software, back up your computer.

Download. After making a backup, go to the http://www.python.org web site and look for the Download area. In here, you’re looking for the pre-built Mac OS X installer. This book will emphasize Python 2.6. In that case, the kit is python-2.6.6-macosx.dmg. When you click on the filename, your browser should start downloading the file. Save it in your downloads folder.

A newer Python 2 (e.g. 2.7) is also a candidate for a download. Python 3, however, has enough differences that it will be confusing; do not download Python 3.

At this point, you have everything you need to install Python:

  • A backup
  • The Python installer

Macintosh Installation

When you double-click the python-2.6.6-macosx.dmg file, it will create a disk image named Python 2.6. This disk image has your license, a ReadMe file, a Build file and the MacPython.mpkg.

When you double-click the Python.mpkg fie, it will take all the necessary steps to install Python on your computer. The installer will take you through seven steps. Generally, you’ll read the messages and

Introduction. Read the message and click Continue.

Read Me. This is the contents of the ReadMe file on the installer disk image. Read the message and click Continue.

License. You can read the history of Python, and the terms and conditions for using it. To install Python, you must agree with the license. When you click Continue, you will get a pop-up window that asks if you agree. Click Agree to install Python.

Select Destination. Generally, your primary disk drive, usually named Macintosh HD will be highlighted with a green arrow. Click Continue.

Installation Type. If you’ve done this before, you’ll see that this will be an upgrade. If this is the first time, you’ll be doing an install. Click the Install or Upgrade button.

You’ll be asked for your password. If, for some reason, you aren’t the administrator for this computer, you won’t be able to install software. Otherwise, provide your password so that you can install software.

Finish Up. The message is usually “The software was successfully installed”. Click Close to finish.

Macintosh Post-Installation

In your Applications folder, you’ll find a Python 2.6 folder, which contains a number of applications.

  • BuildApplet
  • Extras
  • IDLE
  • PythonLauncher
  • Update Shell Profile.command

Once you’ve finished installation, you should check to be sure that everything is working correctly.

Important

Testing

Now you can go to your Applications folder, and double click the IDLE application. This will open two windows, the Python Shell window is what we need, but it is buried under a Console window.

Here’s what you’ll see in the Python Shell window.

Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************

IDLE 2.6.6
>>>

At the top of the window, you’ll see a menu named IDLE with the menu item Quit IDLE. Use this to finish using IDLE for now, and skip to the next chapter.

You may notice a Help menu. This has the Python Docs menu item, which you can access through the menu or by hitting F1. This will launch Safari to show you the Python documents that you also downloaded and installed.

Adding IDLE Without An Install on Mac OS X

If you did an install of Python 2.6, you should have IDLE available in your Python 2.6 folder in the Applications folder. Nothing else needs to be done. Go directly to the next chapter.

If you did not install an upgrade, you will want to add IDLE to your environment. There are two relatively simple approaches.

  • One choice is to move the icon that starts IDLE into your Applications folder.
  • A second choice is put the Python binaries on your PATH. This allows you to easily run IDLE from the Terminal tool.

The following directory has the IDLE program:

/System/Library/Frameworks/Python.framework/Versions/Current/bin/idle2.6

You can do any one of the following alternatives to make IDLE available without a complete installation. Don’t do all of them.

  1. Move the idle icons.

    This is probably the simplest aproach.

    First, create a Python 2.6 folder in your Applications folder.

    To move the existing idle and idle2.6 icons, you’ll have to start from your Macintosh HD, you can locate the bin directory which contains the files named idle and idle2.6.

    Second, drag these two folders into your new Python 2.6 folder.

    Now the IDLE icon is easy to find. You’re ready to move to the next chapter.

  2. Add idle to the PATH.

    This happens automatically as part of installing Python 2.6. You can do this step manually instead of doing a complete installation. However, there is a huge technical hurdle: it’s difficult to edit the hidden files in your home directory. Essentially, the job is to edit your ~/.bash_profile to add the following lines. Because the name begins with a ., it’s considered “hidden”, and most Mac OS tools won’t touch it.

    PATH="/System/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
    PATH="${PATH}:/usr/local/bin"
    export PATH
    

    It’s beyond the scope of this book to address the various tools that can edit files like your ~/.bash_profile.

    Now you can type idle & at the Terminal prompt and run IDLE. You’re ready to move to the next chapter.

GNU/Linux and UNIX Overview

Many GNU/Linux and Unix systems have Python installed. On some older Linuxes [Linuxi? Lini? Linen?] there may be an older version of Python that needs to be upgraded. Here’s what you do to find out whether or not you already have Python.

You’ll need to run the Terminal tool. The GNOME desktop that comes with Red Hat and Fedora has a Start Here icon which displays the applications that are configured into you GNOME environment. The System Tools icon includes the Terminal application. Double click Terminal icon, or pick it off the menu, and you’ll get a window which prompts you by showing something like [slott@linux01 slott]$. In response to this prompt, enter env python, and see what happens.

Here’s what happens when Python is not installed.

slott% env python
tcsh: python: not found

Here’s what you see when there is a properly installed, but out-of-date Python on your GNU/Linux box.

slott% env python
Python 2.3.5 (#1, Mar 20 2005, 20:38:20)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D

In this case, the version number is 2.3.5, which is good, but we need to install an upgrade.

Note that we typed Ctrl-D to finish using Python.

Unix is not Linux. For non-Linux commercial Unix installations (Solaris, AIX, HP/UX, etc.), check with your vendor (Sun, IBM, HP, etc.) It is very likely that they have an extensive collection of open source projects like Python pre-built for your UNIX variant. Getting a pre-built kit from your operating system vendor is the best way to install Python.

YUM Installation

Some Linux distributions use tools like Yum. For example, if you are a Fedora user, you will have Yum. Other Linux distributions have similar tools.

If you have an out-of-date Python, you can enter the following commands in the Terminal window to do an upgrade.

yum upgrade python
yum install tkinter

The first command will upgrade Python to the latest and greatest version.

The second command will assure that the extension package named tkinter is part of your Fedora installation. It is not, typically, provided automatically. You’ll need this to make use of the IDLE program used extensively in later chapters.

Table Of Contents

Previous topic

About Programming

Next topic

Two Minimally-Geeky Problems : Examples of Things Best Done by Customized Software

This Page