Introduction and requirements

Here we describe the compilation and installation procedure for OpenBabel 2.0.2. For a different release, the version number will be different and you should take this in account when reading the instructions below.

The following are optional when compiling Open Babel, but if not installed, fewer features will be available:

Python is required to compile the Python bindings

Perl is required to compile the Perl bindings

If you are compiling directly from the Subversion repository, then you need to create the Python/Perl bindings yourself. To do so, you need to install the latest version of SWIG and to run configure as "configure --enable-maintainer-mode"

libxml2 development headers are required to read/write CML files (the libxml2-dev package in Ubuntu)

zlib.h is required to support reading gzipped files (the zlib1g-dev package in Ubuntu)

If using GCC 3.x to compile (and not GCC 4.x), then the Boost headers are required for certain formats (CML, Chemkin, Chemdraw CDX, MDL RXN and RSMI)

(A3) If you have root permissions, you can install openbabel globally.
As root, run the following command:

make install

Note: This will take about 5 minutes, and will display a large amount of output on the screen.

Install the Python bindings globally

(B1) If you want to use OpenBabel from Python, you now need to compile the python extension. This may require an extra Python package depending on your Linux distribution. For example, for Debian you need the 'python-dev' package (installed using 'apt-get'); for SUSE, you need 'python-devel' (installed using YaST).

Change directory to 'openbabel-2.0.2/scripts/python' and run:

python setup.py build

(B2) To install the python interface globally, as root type:

python setup.py install

(B3) You may need to add the location of libopenbabel.so.1 (on my system, the location is /usr/local/lib) to the environment variable LD_LIBRARY_PATH if you get the following error when you try to import the OpenBabel library at the Python prompt:

If this happens, you should set the value of the MACOSX_DEPLOYMENT_TARGET environment variable to match the MacOSX major version. For example, if you are using MacOSX 10.4.9, set MACOSX_DEPLOYMENT_TARGET to 10.4. Now run 'make' again.

(C2) To install the Perl bindings globally, as root type:

make install

(C3) You may need to add the location of libopenbabel.so.1 (on my system, the location is /usr/local/lib) to the environment variable LD_LIBRARY_PATH if you get an error when you try to import the OpenBabel library in a Perl script.

Installing locally without root access

If you don't have root access, you can still compile and use Open Babel.

(D1) Follow Step A1 above

(D2) Make a local directory to install everything into. In this example, I will use the folder "tree" in my home directory:

mkdir /home/noel/tree

(D3) Instead of Step A2 above, use the 'prefix' option of configure as follows:

(D4) You can now install without root permissions using the following command:

make install

Note: This will take about 5 minutes, and will display a large amount of output on the screen.

This installs the babel executable (and related tools) to /home/noel/tree/bin so you need to add this directory to your PATH in your startup scripts (that is, .bashrc, or whatever):

export PATH=$PATH:/home/noel/tree/bin

Install the Python bindings locally

(E1) To compile the Python extension, follow Step B1 above.

(E2) To install the Python extension, instead of Step B2 above, use the 'prefix' option to setup.py:

python setup.py install --prefix=/home/noel/tree

This installs the Python extension into something like /home/noel/tree/lib/python2.3/site-packages, so you need to add this directory to your PYTHONPATH in your startup scripts (that is, .bashrc, or whatever):

(E3) As described in Step B3 above, you will probably also have to edit the variable LD_LIBRARY_PATH as follows:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/noel/tree/lib

Install the Perl bindings locally

(F1) To compile the Perl extension, instead of Step C1 above, use the 'PREFIX' option to Makefile.PL to specify an install location:

perl Makefile.PL PREFIX=/home/noel/tree
make
make test # (Optional - this runs a few standard tests)

(F2) To install the Perl extension, run the following:

make install

This installs the extension into something like /home/noel/tree/lib/perl/5.8.7, so you need to add "/home/noel/tree/lib/perl" to your PERL5LIB environment variable or specify this location in your Perl scripts as follows:

use lib "/home/noel/tree/lib/perl"; # Must come before "use Chemistry::OpenBabel;"

(F3) As described in Step C3 above, you will probably also have to edit the variable LD_LIBRARY_PATH as follows:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/noel/tree/lib

Advanced Notes

When compiling the Python extension, if you want to link to a version of Open Babel that is not in ../../src (relative to setup.py), /usr/local or /usr (this is the order in which these locations are searched), you should set OPENBABEL_INSTALL to point to the alternative location. There should be an "include/openbabel-2.0" and a "lib" directory at the location pointed to by OPENBABEL_INSTALL.

If you are compiling a development version of OpenBabel, then you need to create the SWIG bindings yourself. Make sure you have the latest version of SWIG installed, and at Step A2 above, run configure as follows: ./configure --enable-maintainer-mode