Importing Brian

After installation, Brian is avaiable in the brian2 package. By doing a wildcard import from this package, i.e.:

from brian2 import *

you will not only get access to the brian2 classes and functions, but also to everything in the pylab package, which includes the plotting functions from matplotlib and everything included in numpy/scipy (e.g. functions such as arange, linspace, etc.). This is the style used in the documentation and in the examples but not in the Brian code itself (see Coding conventions).

If you want to use a wildcard import from Brian, but don’t want to import all the additional symbols provided by pylab, you can use:

from brian2.only import *

Note that whenever you use something different from the most general from brian2 import * statement, you should be aware that Brian overwrites some numpy functions with their unit-aware equivalents (see Units). If you combine multiple wildcard imports, the Brian import should therefore be the last import. Similarly, you should not import and call overwritten numpy functions directly, e.g. by using import numpy as np followed by np.sin since this will not use the unit-aware versions. To make this easier, Brian provides a brian2.numpy_ package that provides access to everything in numpy but overwrites certain functions. If you prefer to use prefixed names, the recommended way of doing the imports is therefore:

import brian2.numpy_ as np
import brian2.only as br2

Note that it is safe to use e.g. np.sin and numpy.sin after a from brian2 import *.