How to fix pysb Exception: The program BioNetGen was not found in the default search path(s) for your operating system

Problem

While running a PySB model, you see an error message such as


Exception: The program BioNetGen was not found in the default search path(s) for your operating system:

/usr/local/share/BioNetGen
/usr/bin
/home/user/.local/bin
/home/user/.pyenv/shims
/home/user/.pyenv/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin

Either install it to one of those paths, or set a custom path using the environment variable BNGPATH or by calling the function pysb.pathfinder.set_path()

Conda users can install BioNetGen using the following command:

conda install -c alubbock bionetgen

Solution

First, clone BioNetGen from the official repository to a folder of your choice. In this example, we’ll use ~/bionetgen:

git clone --depth 1 -b BioNetGen-2.9.2 https://github.com/RuleWorld/bionetgen.git

Then, before running any pysb code, set the BNGPATH environment variable to the path where you cloned BioNetGen by inserting the following Python code:

import os
import os.path
os.environ['BNGPATH'] = os.path.expanduser('~/bionetgen/bng2')

Note that BNGPATH must be set to the bng2 subfolder of the cloned BioNetGen repository!

Re-run your entire program - now, the error should be gone.