libSBML Python API  5.18.0
Accessing libSBML from software

Once the libSBML files are installed, you may need to take additional steps so that software applications can find the libSBML library files at run time. This section provides information about how to do that.

1. Setting your library search path

Installing libSBML puts copies of the libSBML native object files in appropriate destinations on your computer. (By "native object files", we mean files such as libsbml.so, libsbml.5.dylib, libsbml.dll, etc.) On Mac OS X, this should be enough; a software application should be able to find the libSBML library file(s) when it runs. On Linux and Windows, that may not be enough to let a software application find the libSBML library files—you may need to take additional steps. This may be the case even if your application can find other libSBML components such as the language-specific interface (e.g., the libSBML JAR file in the Java case, or the libsbml.py file in the Python case).

If your run-time environment and the run-time environment for your software applications do not know to look in the directory where libSBML was installed, programs that require libSBML will fail to run and report errors about being unable to find libSBML.

How to configure most Linux platforms

There are two common approaches to solving the problem under Linux.

  1. Using ldconfig: Run the program ldconfig as user 'root' on your computer. (Please consult the man page for ldconfig if this is unfamiliar.) This will configure the system for all users.
  2. Setting environment variables: Ensure that each user sets the environment variable LD_LIBRARY_PATH in their terminal shells. If you downloaded a ready-to-run libSBML installer, the default where the libSBML library is installed is /usr/local/lib. If you built libSBML yourself using CMake, the path consists of /lib appended to the value used for the CMAKE_INSTALL_PREFIX configuration variable. If you built libSBML using GNU make, the path is DIR/lib, where DIR is the value used for the configuration option --prefix=DIR.

    For example, suppose you used the default installation prefix /usr/local/. Then in csh-based command shells under Linux, you may have to set the variable as follows (perhaps in your .cshrc file):

    setenv LD_LIBRARY_PATH /usr/local/lib
    

How to configure Microsoft Windows platforms:

Set the PATH environment variable to include the directory of the libSBML native library. To set an environmental variable in Windows, use the System option in the Windows Control Panel.

2. Importing libSBML

As described in the downloading instructions, we provide three ways for you to get the libSBML Python language interface easily without having to configure and build libSBML manually from sources. You can use (1) PyPI, the Python Package Index; (2) binary packages for use with standard Linux installation tools such as yum and apt-get; or (3) executable installers for Windows.

If you used a libSBML Python installer

If you downloaded one of the ready-to-use Python installers for libSBML, you should not need to do anything more: you should be able to access libSBML from your Python interpreter by importing it like any other Python module. In other words, the following should work:

from libsbml import *

If you did not use an installer

In this case, libSBML must first be configured, compiled and installed as described in the building instructions. Once that is done, your Python interpreter will need one more thing to find libSBML: a correctly set PYTHONPATH environment variable. To cope with the fact that different Unix-like systems (including Mac OS X) use different conventions for where they install Python modules, the following is a general-purpose setting for PYTHONPATH. Here, DIR represents the value of the --prefix=DIR option given during configuration of libSBML (the default value is /usr/local) and version is the version of your copy of Python (this might be, e.g., 2.7). If you use sh-based shells such as Bash, put this in your shell's initialization file or execute it in your shell before starting the Python interpreter:
PYSITE=DIR/lib/version/site-packages
PYDIST=DIR/lib/version/dist-packages
export PYTHONPATH=$PYTHONPATH:$PYSITE:$PYSITE/libsbml:$PYDIST:$PYDIST/libsbml
If you use csh-based shells instead of Bash or other sh-based shells, then the appropriate syntax is the following:
set PYSITE = DIR/lib/version/site-packages
set PYDIST = DIR/lib/version/dist-packages
setenv PYTHONPATH ${PYTHONPATH}:${PYSITE}:${PYSITE}/libsbml:${PYDIST}:${PYDIST}/libsbml

Once the PYTHONPATH variable has been set, you should be able to start the Python interpreter and type the following command to import the libSBML package for Python:

from libsbml import *

If Python produces an import error or a failure in linking a new module, it probably means that PYTHONPATH has not been set correctly. It may also mean that the read/write permissions of the installed library files or a directory in the hierarchy containing them are such that you are not allowed to access the files. In that case, please consult your systems administrator or (if you have administrator priviledges) reset the permissions yourself.