XML technologies / XML / Python & XML / Installing Python and XML tools

(Excerpt from “Python & XML” by Christopher A. Jones & Fred L. Drake, Jr.)

This page helps you get started with Python and the extra XML packages used in this book. An Internet connection is needed to download them. Some packages may have additional online instructions worth consulting, since we generally install the latest versions. Those instructions may be newer than the book, so do not ignore them.

Installing Python

Although this is not a Python introduction, we cover installation because you may be upgrading an older Python 2 system. We strongly recommend a newer version for extensive XML work. Python 2.0 or later is sufficient for the book’s examples, so you need not reinstall if you already have it.

Python is available at python.org for Windows, Unix and other platforms. Download links ask you to choose a version. After selecting the latest stable release, choose a Windows installer, source code or possibly Linux or other platform packages. Version 2.1.1 is the newest at press time; Python 2.2 is expected soon and should be fully compatible with the book.

Windows

On Windows, download and run the installer. The remaining steps follow the familiar Windows installation process. At completion, the interpreter is available in C:\Python21 unless you selected another directory. The directory’s version number may differ with the installed release but never exceeds two digits.

Start Windows Python programs by double-clicking the executable’s icon or typing this at the command line:

 C:\mein-dir> c:\python21\python meinProgramm.py 

For command-line use, you will probably want to add Python’s installation directory to the environment variable Path. Windows 2000 requires the Control Panel. From Start choose Settings ➝ Control Panel to open the System panel. Click Advanced, then Environment Variables. In the dialog’s lower section, titled System Variables, locate and select the variable Path and click Edit.... In the field Variable Value, append the full installation path to the directory list, separated by a semicolon (;). After editing Path, click the OK button in each open dialog. Other Windows versions let you edit the Path variable in the file autoexec.bat.

Linux and Unix

For Linux or Unix, both called Unix below, we suggest downloading source in .tar.gz format. Unpack it like this, for example:

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

You now have a fresh Python directory. Enter it with the command cd. On most Unix machines, installation requires only:

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

The archive Python-2.1.1.tgz installs Python in /usr/local/bin/python. Depending on security settings, you will probably need to be user root to install it.

If you already have a Python 1.x installation, check after running make install that the new interpreter is on your execution path:

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

If the result is

 /usr/bin/python 

consider adding /usr/local/bin to your environment variable PATH before /usr/bin. Some Linux installations require older Python. Until distributors update them, keeping several versions may be better than replacing the distribution’s installation.

Alternatively, remove old versions before installing the newest or unpack the new one at the same base path. If the operating system does not need the older version, invoking python should cause no interpreter conflicts. Source installation preserves older versions, which can still be launched by specifying the major.minor part of the version in the command, for example python2.1.

If upgrading matters, consult the source distribution’s documentation—the README file, Misc/NEWS and other documents—and the release notes at python.org.

Installing PyXML

Once Python is installed, adding packages is relatively easy. PyXML uses Python’s distribution tools package distutils. Obtain PyXML from its SourceForge project page, checking downloads for the newest version, 0.6.6 at publication.

Windows has an installer for each supported Python version. For bug-fix releases such as 2.1.1, use the installer for the corresponding feature release, 2.1 here, since binary compatibility is preserved. Run the installer normally; it finds matching Python installations and lets you select which should receive PyXML. Installation then continues and makes PyXML available to that interpreter.

On Unix, download a .tar.gz archive of your chosen version and unpack it as for Python’s source. Make the distribution’s top directory your working directory. It contains the Python script setup.py; run it with the interpreter receiving PyXML and the command-line argument build:

 $> python setup.py build 

This builds every PyXML component from Python or C source. Then install the package for Python to use, usually as a privileged user:

$> su
Password:
%> python setup.py install

Ensure the privileged user uses the same interpreter as the user who built PyXML.

Installing 4Suite

4Suite includes various DOM implementations optimized for different applications, and supports XPath, XLink, XPointer, XSLT and RDF. Source and binary packages are available for Windows and Linux. On Windows, download the binary installer and follow its instructions. Adding its directory to your path in autoexec.bat or NT environment variables lets you use the 4xslt script for command-line XSLT transformations. On Linux choose source or binary packages. The README file has the latest installation instructions, but as with most recent Python source packages, you can use the distribution tools (distutils); see PyXML installation for details.

After installation, the 4xslt script supports command-line transformations, provided its directory is in your environment variable PATH.

  

 

 

 

back to top