gtk import Segmentation fault

When I tried to run my program (ModeRator) I get this error:
/usr/lib64/python2.7/site-packages/gobject/constants.py:24: Warning: g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
import gobject._gobject
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for type `PyGtkGenericCellRenderer' is smaller than the parent type's `GtkCellRenderer' class size
from gtk import _gtk
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion `node != NULL' failed
from gtk import _gtk
Segmentation fault (core dumped)

I ‘fixed’ the problem by disabling the import of matplotlib

It turns out that it is possible to import only one of them:
from gi.repository import GObject, Gtk
or
import matplotlib.pyplot as plt

Comment out one of these lines end the error is gone!
Better explanation of problems like this is found here: http://blog.rabbitvcs.org/archives/312.

How to install libSBML in Fedora 18 with Python bindings

Install compiler
yum install gcc-c++
yum groupinstall "Development Tools"

Install some additional packages if needed
yum install python-devel
yum install libxml2-devel
yum install swig

Compile and install libSBML
Go to the directory where you have exctracted libsbml source and run these 3 commands
./configure --with-python
make
make install

Make libsbml accessible to Python
export PYTHONPATH=/usr/local/lib64/python2.7/site-packages/libsbml
Or fix the path right from your python script
import sys
sys.path.append('/usr/local/lib64/python2.7/site-packages/libsbml')

You can get and set environment variables via os.environ:
import os
os.environ['PYTHONPATH'] = '/usr/local/lib/python2.7/dist-packages/libsbml'

But since your interpreter already runs, this will have no effect.

For whatever reason, in Fedora the library file is _libsbml, not libsml. To use libsbml in Fedora import it like this:
import _libsbml

Installing libsbml with python support on Debian wheezy

Installing libSBML on Debian begins the same way as on Ubuntu. First follow the instructions in this post.

After compiling and installing, libsbml on Ubuntu should be working.

In Debian, if you try to import libsbml, you get the following error:
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/libsbml/__init__.py", line 27, in
_libsbml = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/libsbml/__init__.py", line 23, in swig_import_helper
_mod = imp.load_module('_libsbml', fp, pathname, description)
ImportError: libsbml.so.5: cannot open shared object file: No such file or directory

To get it working you have to set PYTHONPATH variable:
In commandline:
export PYTHONPATH=/usr/local/lib/python2.7/dist-packages/libsbml

It is also possible to modify environment variable from within python code:
import sys
sys.path.append('/usr/local/lib64/python2.7/site-packages/libsbml')

You can get and set environment variables via os.environ:
import os
os.environ['PYTHONPATH'] = '/usr/local/lib/python2.7/dist-packages/libsbml'

But since your interpreter already runs, this will have no effect.

LibSBML does not support chemical formulas for species

Yes, this is true. You can not store metabolites chemical formulas directly in SBML. I have seen various approaches, like, adding chemical formula to the name of the metabolite or storing formula in the htmlNotes tags.
I have been struggling to find an appropriate way to read&write chemical formulas in SBML files until my recent correspondance with authors of libSBML.

Quoting Sarah Keating:

The most robust way to currently store this information is to use a miriam compliant annotation to point to a database/resource that specifies the formula. Section 6 of the SBML Level 3 Version 1 Core specification details of this type of annotation and libSBML provides an API that allows users to interact with the annotation via a class CVTerms (see the addCVTerms example).
Directly adding chemicalFormula to the Species element is being facilitated by the SBML L3 Flux Balance Constraints package (http://sbml.org/Documents/Specifications/SBML_Level_3/Packages/Flux_Balance_Constraints_%28flux%29). LibSBML does provide “experimental” support for this package.

How to create an SBML file using libSBML in Python

This tutorial is intended as a quick introduction on how to create an SBML file using libSBML. For a full developer’s guide, please see libSBML Python API.

from libsbml import *
document = SBMLDocument()
model = document.createModel(2, 4) # SBML level and version

##First you have to create compartments
c1 = model.createCompartment()
c1.setName('Forest')
c1.setId('comp_FOREST')

## Set the volume of compartments
c1.setVolume(1000)

## Continue with other compartments
c2 = model.createCompartment()
c2.setName('Meadow')
c2.setId('comp_Meadow')
c2.setVolume(1000)

## When you have finished with compartments, proceed with species.
s1 = model.createSpecies()
s1.setName('Foxes')
s1.setId('spec_FOXES')
s1.setCompartment('comp_FOREST')
s1.setInitialAmount(10)

s2 = model.createSpecies()
s2.setName('Rabbits')
s2.setId('spec_RABBITS')
s2.setCompartment('comp_FOREST')
s2.setInitialAmount(50)

s3 = model.createSpecies()
s3.setName('Snakes')
s3.setId('spec_Snakes')
s3.setCompartment('comp_Meadow')
s3.setInitialAmount(100)

## When you are done with compartments and species, create reactions.
r1 = model.createReaction()
r1.setName('Foxes eat rabbits')
r1.setId('R1')

## Create reactants and products
reac1 = r1.createReactant()
reac1.setSpecies('spec_RABBITS')
prod1 = r1.createProduct()
prod1.setSpecies('spec_FOXES')

## if necessary, set Stoichiometry
reac1.setStoichiometry(2) # 2 rabbits
prod1.setStoichiometry(1) # 1 fox

Notice that we create seemingly independent objects for comprartments, reaction, reactant and product. We set some values to the properties of these objects and never actually add these elements to the model. Thats because they are automatically added. You can try this inside a loop and it will still work.

##Now when you have done whith your model you have to add it to the document.
document.setModel(model)

## If you wish you can add optional information.
model.setName('My test model')
model.setId('MyModelID')

##Save to file.
writeSBMLToFile(document,'name_of_your_model.xml')

That’s it! Copy&paste this code and try it yourself!
Please note that this tutorial is realy basic. For more comprehensive examples, please see the examples/ folder in the libSBML source tree.