Installing Python

While this book is not an introductory text on Python, we review the installation process since you may be upgrading an older system to use Python 2; using one of the more recent versions of Python is strongly recommended if you’ll be doing much work with XML. If you already have Python Version 2.0 or newer installed, you do not need to install a new version to use the examples in this book.

Python is available from http://www.python.org/ for both Windows and Unix platforms. If you follow the download links on the Python web site, you are prompted to select a version. After selecting the most recent stable version, you are presented with selections for the Windows Installer, source code, and possibly installable packages for Linux or other platforms. (Version 2.1.1 is the most recent version available as this book goes to press, but Python 2.2 is expected to be available shortly thereafter and is expected to be fully compatible with everything in this book.)

Windows

If you are installing on Windows, download the Windows Installer and run it. The remainder of the installation process will seem very familiar to you as a standard Windows installation procedure. When the process is complete, the Python executable will be available to you in the C:Python21 directory unless you have elected a different location during the installation process. The trailing version number in the directory name may be different depending on the version of Python you install, but will never be more than two digits long.

You can run Python programs on Windows either by double-clicking the icon of the executable, or at the command line by typing:

C:my-dir> c:python21python myProgram.py

If you want to run Python from the command line, you probably want to add Python’s installation directory to your Path environment variable. If you’re using Windows 2000, this needs to be done using the Control Panel. From Start, select Settings Control Panel to open the System panel. Select the Advanced tab, and then choose Environment Variables. In the lower portion of the dialog, labeled System Variables, locate and select the Path variable, then choose Edit. In the Variable Value entry field, add the full name of the installation directory to the list of directories, separated from the others by a semi-colon (;). When you’re done editing the Path value, click the Ok button for each of the three open dialogs. For other versions of Windows, you can edit the setting for the Path variable in your autoexec.bat file.

Linux and Unix

If you are installing on Linux or Unix (collectively referred to as Unix from now on), we suggest downloading the source code in .tar.gz format. You can unpack the package with something along the lines of:

$> gzip -dc Python-2.1.1.tgz | tar xf -

Either way, you wind up with a fresh new Python directory. Once created, use the cd command to go inside. On most Unix machines, all that is needed to build Python is:

$> ./configure
$> make
$> su
password:
$> make install

The Python-2.1.1.tgz archive installs Python in /usr/local/bin/python. Depending on the security of your system, you’ll likely need to be user root in order to install Python.

If you have an existing Python 1.x installation, after running make install, you may want to check that the new version of Python is in your execution path:

$> which python
/usr/local/bin/python

If you get back the following:

/usr/bin/python

you may want to consider adding /usr/local/bin to your PATH environment variable before /usr/bin. Some Linux installations require an older version of Python; until those installations are updated by the vendors, it may be better to install multiple versions than to replace an installation provided as part of the Linux distribution.

Other options include removing older versions before installing the latest and greatest, or deploying the new version into the same base path as the old. Unless your operating system requires the older version, there should be no conflicts aside from the executable loaded when you run python from the command line; older versions remain in place if installing from source. You can still run the older version by including the major.minor portion of the version number in the command line (for example, python2.1). In either case, if upgrading is an issue for you, the documentation included with the source distribution itself (the README file, Misc/NEWS, and other documents), as well as the release notes on http://www.python.org/ should be consulted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.74.25