previous | Table of Contents | next

# Chapter 2: Installation

The Python `Distutils` are used to build and install `PyTables`, so it is fairly simple to get the application up and running. If you want to install the package from sources go to the next section. But if you are running Windows and want to install precompiled binaries jump to section 2.2). In addition, packages are starting to appear in different Linux distributions, like for instance `RockLinux`, `Debian`, `Fedora` or `Gentoo`. There also packages for other Unices too, like `FreeBSD` or `MacOSX`

## 2.1 Installation from source

These instructions are for both Unix/Linux and Windows systems. If you are using Windows, it is assumed that you have a recent version of `MS Visual C++` (>= 6.0) compiler installed. A `GCC` compiler is assumed for Unix, but other compilers should work as well.

Extensions in `PyTables` have been developed in Pyrex (see ) and C language. You can rebuild everything from scratch if you have Pyrex installed, but this is not necessary, as the Pyrex compiled source is included in the distribution.

To compile `PyTables` you will need a recent version of the `HDF5` (C flavor) library and the `numarray` (see ) package. Although you won't need `Numerical Python` (see ) in order to compile PyTables, it is supported; you only need a reasonably recent version of it (>= 21.x) if you plan on using its methods in your applications. PyTables has been successfully tested with Numeric 21.3, 22.0 and 23.0. If you already have `Numeric` installed, the test driver module will detect it and will run the tests for `Numeric` automatically.

### 2.1.1 Prerequisites

First, make sure that you have `HDF5 1.6.2` and `numarray 1.0` or higher installed (I'm using `HDF5 1.6.2` and `numarray 1.0` currently). If you don't, you can find them at `http://hdf.ncsa.uiuc.edu/HDF5` and `http://www.pfdubois.com/numpy`.

Compile and install these packages (but see section 2.2.1 for instructions on how to install precompiled binaries if you are not willing to compile the prerequisites on Windows systems).

For compression (and possibly improved performance), you will need to install the `Zlib` (see ), which is also required by `HDF5` as well. You may also optionally install the excellent `LZO` and `UCL` compression libraries (see and section 5.2).

Unix

  `setup.py` will detect `HDF5`, `LZO` or `UCL` libraries and include files under `/usr` or `/usr/local`; this will cover most manual installations as well as installations from packages. If `setup.py` can't find `libhdf5` or `libz` (or `liblzo` or `libucl` that you may wish to use) or if you have several versions of a library installed and want to use a particular one, then you can set the path to the resource in the environment, setting the values of the `HDF5_DIR`, `LZO_DIR` or `UCL_DIR` environment variables to the path to the particular resource. You may also specify the locations of the resource root directories on the `setup.py` command line. For example:

      		--hdf5=/stuff/hdf5-1.6.2
      		--lzo=/stuff/lzo-1.08
      		--ucl=/stuff/ucl-1.02

  If your `HDF5` library was built as a shared library not in the runtime load path, then you can specify the additional linker flags needed to find the shared library on the command line as well. For example:

      		  --lflags="-Xlinker -rpath -Xlinker /stuff/hdf5-1.6.2/lib"

  or perhaps just

      		  --rpath="/stuff/hdf5-1.6.2/lib"

  Check your compiler and linker documentation as well as the Python `Distutils` documentation for the correct syntax.
  It is also possible to link with specific libraries by setting the `LIBS` environment variable:

      		  LIBS="hdf5-1.6.5"
      		  LIBS="hdf5-1.6.5 nsl"

Windows

  Once you have installed the prerequisites, `setup.py` needs to know where the necessary library stub (`.lib`) and header (`.h`) files are installed. Set the following environment variables:

  HDF5_DIR
    Points to the root HDF5 directory (where the include/ and dll/ directories can be found). Mandatory.
  LZO_DIR
    Points to the root LZO directory (where the include/ and lib/ directories can be found). Optional.
  UCL_DIR
    Points to the root UCL directory (where the include/ and lib/ directories can be found). Optional.
  For example:

      		  set HDF5_DIR=c:\stuff\5-162-win2k\c\release
      		  set UCL_DIR=c:\stuff\ucl-1-02
      		  set LZO_DIR=c:\stuff\lzo-1-08

  Or, you can pass this information to `setup.py` by setting the appropriate arguments on the command line. For example:

      		--hdf5=c:\stuff\5-162-win2k\c\release
      		--lzo=c:\stuff\lzo-1-08
      		--ucl=c:\stuff\ucl-1-02

### 2.1.2 `PyTables` package installation

Once you have installed the HDF5 library and numarray packages, you can proceed with the `PyTables` package itself:

1. Run this command from the main `PyTables` distribution directory, including any extra command line arguments as discussed above:

       		  python setup.py build_ext --inplace

   Depending on the compiler flags used when compiling your Python executable, there may appear many warnings. Don't worry, almost all of them are caused by variables declared but never used. That's normal in Pyrex extensions.

2. To run the test suite, change into the test directory and execute this command:

   Unix
     In the shell `sh` and its variants:

         		    PYTHONPATH=..
         		    export PYTHONPATH
         		    python test_all.py

   Windows
     Open a DOS terminal and type:

         		    set PYTHONPATH=..
         		    python test_all.py

   If you would like to see verbose output from the tests simply add the flag `-v` and/or the word `verbose` to the command line. You can also run only the tests in a particular test module. For example, to execute just the `types` test:

       		  python test_types.py -v

   If a test fails, please enable verbose output (the `-v` flag and `verbose` option), run the failing test module again, and, very important, get your `PyTables` version information by running the command:

       		  python test_all.py --show-versions-only

   and send back the output to developers so that we may continue improving `PyTables`.

   If you run into problems because Python can't load the HDF5 library or other shared libraries:

   Unix
     Try setting the LD_LIBRARY_PATH environment variable to point to the directory where the missing libraries can be found.
   Windows
     Put the DLL libraries (`hdf5dll.dll` and, optionally, `lzo.dll` and `ucl.dll`) in a directory listed in your `PATH` environment variable. The `setup.py` installation program will print out a warning to that effect if the libraries can't be found.
3. To install the entire `PyTables` Python package, change back to the root distribution directory and run the following command (make sure you have sufficient permissions to write to the directories where the `PyTables` files will be installed):

       		  python setup.py install

   Of course, you will need super-user privileges if you want to install `PyTables` on a system-protected area. You can select, though, a different place to install the package using the `--prefix` flag:

       		  python setup.py install --prefix="/home/myuser/mystuff"

   Have in mind, however, that if you use the `--prefix` flag to install in a non-standard place, you should properly setup your `PYTHONPATH` environment variable, so that the Python interpreter would be able to find your new `PyTables` installation.
   You have more installation options available in the distutils package. Issue a:

       		  python setup.py install --help

   for more information on that subject.

That's it! You can skip to the next chapter to learn how to use PyTables `PyTables`.

## 2.2 Binary installation (Windows)

This section is intended for installing precompiled binaries on Windows platforms. You may also find it useful for instructions on how to install binary prerequisites even if you want to compile `PyTables` itself on Windows.

### 2.2.1 Windows prerequisites

First, make sure that you have HDF5 1.6.2 or higher and numarray 1.0 or higher installed (I'm using HDF5 1.6.2 and numarray 1.0 currently). If don't, you can find them at `http://hdf.ncsa.uiuc.edu/HDF5` and `http://sourceforge.net/projects/numpy/`. Download the binary packages (or sources, if you want to compile everything yourself) and install them.

For the HDF5 it should be enough to manually copy the `hdf5dll.dll`, `zlib1.dll` and `szipdll.dll` files to a directory in your `PATH` environment variable (for example `C:\WINDOWS\SYSTEM`).

Caveat: When downloading the binary distribution for HDF5 libraries, select one compiled with MSVC 6.0, such as the package `5-162-win2k.zip`, regardless of whether you are using Win2k or WinXP (it should work fine on both). The file `5-162-winxp-net.zip` was compiled with the MSVC 7.0 (aka "`.NET`") and does not work well with the PyTables binary (which has been generated with MSVC 6.0). You have been warned!

To enable compression with optional LZO and UCL libraries (see the section 5.2 for hints about how they may be used to improve performance), fetch and install the `LZO` and `UCL` binaries from:
`http://gnuwin32.sourceforge.net/`. Normally, you will only need to fetch and install the
`<package>-<version>-bin.zip` file and copy the `lzo.dll` or `ucl.dll` files in a directory in the `PATH` environment variable, so that they can be found by the `PyTables` extensions.

Note: If you are reading this because you have been redirected from the section 2.1 (Installation from source), some of the headers you will need are in the `<package>-<version>-lib.zip` file.

### 2.2.2 `PyTables` package installation

Download the `tables-<version>.win32-py<version>.exe`
(`tables-<version>-LU.win32-py<version>.exe` if you want support for LZO and UCL libraries) file and execute it.

You can (you should) test your installation by unpacking the source tar-ball, changing to the `test/` subdirectory and executing the `test_all.py` script. If all the tests pass (possibly with a few warnings, related to the potential unavailability of LZO and UCL libs) you already have a working, well-tested copy of `PyTables` installed! If any test fails, please try to locate which test module is failing and execute:

    	      python test_<module>.py -v verbose

and also:

    	      python test_all.py --show-versions-only

and mail the output to the developers so that the problem can be fixed in future releases.

That's it! Now, proceed to the next chapter to see how to use `PyTables`.

previous | Table of Contents | next