You are here: Home Dive Into Python 3

Difficulty level: ♦♢♢♢♢

Installing Python

Tempora mutantur nos et mutamur in illis. (Times change, and we change with them.)
— ancient Roman proverb

 

Diving in

Welcome to Python 3. Let's dive in. In this chapter, you'll install the version of Python 3 that's right for you.

Which Python Is Right For You?

The first thing you need to do with Python is install it. Or do you?

If you're using an account on a hosted server, your ISP may have already installed Python 3. If you’re running Linux at home, you may already have Python 3, too. Most popular GNU/Linux distributions come with Python 2 in the default installation; a small but growing number of distributions also include Python 3. (As you’ll see in this chapter, you can have more than one version of Python installed on your computer.) Mac OS X includes a command-line version of Python 2, but as of this writing it does not include Python 3. Microsoft Windows does not come with any version of Python. But don’t despair! You can point-and-click your way through installing Python, regardless of what operating system you have.

The easiest way to check for Python 3 on your Linux or Mac OS X system is to get to a command line. On Linux, look in your Applications menu for a program called Terminal. (It may be in a submenu like Accessories or System.) On Mac OS X, there is an application called Terminal.app in your /Application/Utilities/ folder.

Once you’re at a command line prompt, just type python3 (all lowercase, no spaces) and see what happens. On my home Linux system, Python 3 is already installed, and this command gets me into the Python interactive shell.

mark@atlantis:~$ python3
Python 3.0.1+ (r301:69556, Apr 15 2009, 17:25:52)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

(Type exit() and press ENTER to exit the Python interactive shell.)

My web hosting provider also runs Linux and provides command-line access, but my server does not have Python 3 installed. (Boo!)

mark@manganese:~$ python3
bash: python3: command not found

So back to the question that started this section, “Which Python is right for you?” The answer is whichever one runs on the computer you already have.

[Read on for Windows instructions, or skip to Installing on Mac OS X, Installing on Ubuntu Linux, or Installing on Other Platforms.]

Installing on Microsoft Windows

Windows comes in two architectures these days: 32-bit and 64-bit. Of course, there are lots of different versions of Windows — XP, Vista, Windows 7 — but Python runs on all of them. The more important distinction is 32-bit v. 64-bit. If you have no idea what architecture you’re running, it’s probably 32-bit.

Visit python.org/download/ and download the appropriate Python 3 Windows installer for your architecture. Your choices will look something like this:

I don’t want to include direct download links here, because minor updates of Python happen all the time and I don’t want to be responsible for you missing important updates. You should always install the most recent version of Python 3.x unless you have some esoteric reason not to.

  1. [Windows dialog: open file security warning]

    Once your download is complete, double-click the .msi file. Windows will pop up a security alert, since you’re about to be running executable code. The official Python installer is digitally signed by the Python Software Foundation, the non-profit corporation that oversees Python development. Don’t accept imitations!

    Click the Run button to launch the Python 3 installer.

  2. [Python installer: select whether to install Python 3.1 for all users of this computer]

    The first question the installer will ask you is whether you want to install Python 3 for all users or just for you. The default choice is “install for all users,” which is the best choice unless you have a good reason to choose otherwise. (One possible reason why you would want to “install just for me” is that you are installing Python on your company’s computer and you don’t have administrative rights on your Windows account. But then, why are you installing Python without permission from your company’s Windows administrator? Don’t get me in trouble here!)

    Click the Next button to accept your choice of installation type.

  3. [Python installer: select destination directory]

    Next, the installer will prompt you to choose a destination directory. The default for all versions of Python 3.1.x is C:\Python31\, which should work well for most users unless you have a specific reason to change it. If you maintain a separate drive letter for installing applications, you can browse to it using the embedded crontrols, or simply type the pathname in the box below. You are not limited to installing Python on the C: drive; you can install it on any drive, in any folder.

    Click the Next button to accept your choice of destination directory.

  4. [Python installer: customize Python 3.1]

    The next page looks complicated, but it’s not really. Like many installers, you have the option not to install every single component of Python 3. If disk space is especially tight, you can exclude certain components.

  5. [Python installer: disk space requirements]

    If you’re unsure how much disk space you have, click the Disk Usage button. The installer will list your drive letters, compute how much space is available on each drive, and calculate how much would be left after installation.

    Click the OK button to return to the “Customizing Python*#8221; page.

  6. [Python installer: removing Test Suite option will save 7908KB on your hard drive]

    If you decide to exclude an option, select the drop-down button before the option and select “Entire feature will be unavailable.” For example, excluding the test suite will save you a whopping 7908KB of disk space.

    Click the Next button to accept your choice of options.

  7. [Python installer: progress meter]

    The installer will copy all the necessary files to your chosen destination directory. (This happens so quickly, I had to try it three times to even get a screenshot of it!)

  8. [Python installer: installation completed. Special Windows thanks to Mark Hammond, without whose years of freely shared Windows expertise, Python for Windows would still be Python for DOS.]

    Click the Finish button to exit the installer.

  9. [Windows Python Shell, a graphical interactive shell for Python]

    In your Start menu, there should be a new item called Python 3.1. Within that, there is a program called IDLE. Select this item to run the interactive Python Shell.

[Skip to using the Python Shell]

Installing on Mac OS X

All modern Macintosh computers use the Intel chip (like most Windows PCs). Older Macs used PowerPC chips. You don’t need to understand the difference, because there’s just one Mac Python installer for all Macs.

Visit python.org/download/ and download the Mac installer. It will be called something like Python 3.1 Mac Installer Disk Image, although the version number may vary. Be sure to download version 3.x, not 2.x.

  1. [contents of Python installer disk image]

    Your browser should automatically mount the disk image and open a Finder window to show you the contents. (If this doesn’t happen, you’ll need to find the disk image in your downloads folder and double-click to mount it. It will be named something like python-3.1.dmg.) The disk image contains a number of text files (Build.txt, License.txt, ReadMe.txt), and the actual installer package, Python.mpkg.

    Double-click the Python.mpkg installer package to launch the Mac Python installer.

  2. [Python installer: welcome screen]

    The first page of the installer gives a brief description of Python itself, then refers you to the ReadMe.txt file (which you didn’t read, did you?) for more details.

    Click the Continue button to move along.

  3. [Python installer: information about supported architectures, disk space, and acceptable destination folders]

    The next page actually contains some important information: Python requires Mac OS X 10.3 or later. If you are still running Mac OS X 10.2, you should really upgrade. Apple no longer provides security updates for your operating system, and your computer is probably at risk if you ever go online. Also, you can’t run Python 3.

    Click the Continue button to advance.

  4. [Python installer: software license agreement]

    Like all good installers, the Python installer displays the software license agreement. Python is open source, and its license is approved by the Open Source Initiative. Python has had a number of owners and sponsors throughout its history, each of which has left its mark on the software license. But the end result is this: Python is open source, and you may use it on any platform, for any purpose, without fee or obligation of reciprocity.

    Click the Continue button once again.

  5. [Python installer: dialog to accept license agreement]

    Due to quirks in the standard Apple installer framework, you must “agree” to the software license in order to complete the installation. Since Python is open source, you are really “agreeing” that the license is granting you additional rights, rather than taking them away.

    Click the Agree button to continue.

  6. [Python installer: standard install screen]

    The next screen allows you to change your install location. You must install Python on your boot drive, but due to limitations of the installer, it does not enforce this. In truth, I have never had the need to change the install location.

    From this screen, you can also customize the installation to exclude certain features. If you want to do this, click the Customize button; otherwise click the Install button.

  7. [Python installer: custom install screen]

    If you choose a Custom Install, the installer will present you with the following list of features:

    Click the Install button to continue.

  8. [Python installer: dialog to enter administrative password]

    Because it installs system-wide frameworks and binaries in /usr/local/bin/, the installer will ask you for an administrative password. There is no way to install Mac Python without administrator privileges. (FIXME really?)

    Click the OK button to begin the installation.

  9. [Python installer: progress meter]

    The installer will display a progress meter while it installs the features you’ve selected.

  10. [Python installer: install succeeded]

    Assuming all went well, the installer will give you a big green checkmark to tell you that the installation completed successfully.

    Click the Close button to exit the installer.

  11. [contents of /Applications/Python 3.1/ folder]

    Assuming you didn’t change the install location, you can find the newly installed files in the Python 3.1 folder within your /Applications folder. The most important piece is IDLE, the graphical Python Shell.

    Double-click IDLE to launch the Python Shell.

  12. [Mac Python Shell, a graphical interactive shell for Python]

    The Python Shell is where you will spend most of your time exploring Python. Examples throughout this book will assume that you can find your way into the Python Shell.

[Skip to using the Python Shell]

Installing on Ubuntu Linux

FIXME

  1. [Add/Remove: Canonical-maintained applications]

  2. [Add/Remove: all open source applications]

  3. [Add/Remove: search for Python 3]

  4. [Add/Remove: select Python 3.0 package]

  5. [Add/Remove: select IDLE for Python 3.0 package]

  6. [Add/Remove: apply changes]

  7. [Add/Remove: download progress meter]

  8. [Add/Remove: installation progress meter]

  9. [Add/Remove: new applications have been installed]

  10. [Linux Python Shell, a graphical interactive shell for Python]

[Skip to using the Python Shell]

Installing on Other Platforms

FIXME

Using The Python Shell

FIXME

Python Editors and IDEs

FIXME

http://wiki.python.org/moin/PythonEditors
http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
http://pydev.sourceforge.net/
http://www.activestate.com/komodo/
http://www.activestate.com/activepython/

© 2001–9 Mark Pilgrim