Installing Python packages

The following are generic instructions for installing a python package that is provided as source-code.

For concreteness we will illustrate this process for the biopython package. A package that is provided as source-code is typically named something like

biopython-1.54b.tar.gz or biopython-1.54b.zip

depending on which program was used to package the package. The first part of the name is the package name, followed by its version (the b in this case stands for "beta"). First move the source code to your directory of choice. Depending on the extension use an appropriate program to "unpack" the contents of the package (tar -xzf for files with the extension ".tar.gz" and unzip for zip files).

Let's look inside the directory.

The most important file there is called "setup.py". This file is used to perform the installation process. Which is composed two steps:

  • python setup.py build
    This "builds" the package, which may include compilation if the package contains c/c++ code. On OS-X you will need Apple's Xcode (usually bundled on your OS install disk).
  • sudo python setup.py install
    This installs the package in one of the standard locations where python packages are installed in your system. This typically requires root access, which is why the sudo command is used.

Some packages (like biopython) provide the option of testing that everything works correctly by running: python setup.py test

More complete information is found in the Python documentation.