libSBML Python API
5.18.0
|
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.
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.
There are two common approaches to solving the problem under Linux.
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.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
/lib
appended to the value used for the
CMAKE_INSTALL_PREFIX
/lib
--prefix=
DIR For example, suppose you used the default installation prefix
. 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
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.
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 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 *
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/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/libsbmlIf 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.