Installation
There are various ways to install Brian, and we recommend that you chose the installation method that
they are most familiar with and use for other Python packages. If you do not yet have Python installed on
your system (in particular on Windows machines), you can install Python and all of Brian’s dependencies
via the Anaconda distribution. You can then install
Brian with the conda
package manager as detailed below.
Note
You need to have access to Python >=3.7 (see Brian’s support policy). In particular, Brian no longer supports Python 2 (the last version to support Python 2 was Brian 2.3). All provided Python packages also require a 64 bit system, but every desktop or laptop machine built in the last 10 years (and even most older machines) is 64 bit compatible.
If you are relying on Python packages for several, independent projects, we recommend that you make use
of separate environments for each project. In this way, you can safely update and install packages for
one of your projects without affecting the others. Both, conda
and pip
support installation in
environments – for more explanations see the respective instructions below.
Standard install
We recommend installing Brian into a separate environment, see conda’s documentation for more details. Brian 2 is not part of the main Anaconda distribution, but built using the community-maintained conda-forge project. You will therefore have to to install it from the conda-forge channel. To do so, use:
conda install -c conda-forge brian2
You can also permanently add the channel to your list of channels:
conda config --add channels conda-forge
This has only to be done once. After that, you can install and update the brian2 packages as any other Anaconda package:
conda install brian2
We recommend installing Brian into a separate “virtual environment”, see the
Python Packaging User Guide
for more information.
Brian is included in the PyPI package index: https://pypi.python.org/pypi/Brian2
You can therefore install it with the pip
utility:
python -m pip install brian2
In rare cases where your current environment does not have access to the pip
utility, you first
have to install pip
via:
python -m ensurepip
If you are using a recent Debian-based Linux distribution (Debian itself, or one if its derivatives like Ubuntu or Linux Mint), you can install Brian using its built-in package manager:
sudo apt install python3-brian
Brian releases get packaged by the Debian Med team, but note that it might take a while until the most recent version shows up in the repository.
If you are using Fedora Linux, you can install Brian using its built-in package manager:
sudo dnf install python-brian2
Brian releases get packaged by the NeuroFedora team, but note that it might take a while until the most recent version shows up in the repository.
Spack is a flexible package manager supporting multiple versions, configurations, platforms, and compilers.
After setting up Spack you can install Brian with the following command:
spack install py-brian2
Updating an existing installation
How to update Brian to a new version depends on the installation method you used previously. Typically, you can run the same command that you used for installation (sometimes with an additional option to enforce an upgrade, if available):
Depending on whether you added the conda-forge
channel to the list of channels
or not (see above), you either have to include it in the update command again or
can leave it away. I.e. use:
conda update -c conda-forge brian2
if you did not add the channel, or:
conda update brian2
if you did.
Use the install command together with the --upgrade
or -U
option:
python -m pip install -U brian2
Update the package repository and ask for an install. Note that the package will
also be updated automatically with commands like sudo apt full-upgrade
:
sudo apt update
sudo apt install python3-brian
Update the package repository (not necessary in general, since it will be updated
regularly without asking for it), and ask for an update. Note that the package will
also be updated automatically with commands like sudo dnf upgrade
:
sudo dnf check-update python-brian2
sudo dnf upgrade python-brian2
Requirements for C++ code generation
C++ code generation is highly recommended since it can drastically increase the speed of simulations (see Computational methods and efficiency for details). To use it, you need a C++ compiler and Cython (automatically installed as a dependency of Brian).
On Linux and Mac OS X, the conda package will automatically install a C++ compiler.
But even if you install Brian in a different way, you will most likely already have a
working C++ compiler installed on your system (try calling g++ --version
in a terminal). If not, use your distribution’s package manager to install a g++
package.
On Windows, Runtime code generation (i.e. Cython) requires the Visual Studio compiler, but you do not need a full Visual Studio installation, installing the much smaller “Build Tools” package is sufficient:
Install the Microsoft Build Tools for Visual Studio.
In Build tools, install C++ build tools and ensure the latest versions of MSVCv… build tools and Windows 10 SDK are checked.
Make sure that your
setuptools
package has at least version 34.4.0 (useconda update setuptools
when using Anaconda, orpython -m pip install --upgrade setuptools
when using pip).
For Standalone code generation, you can either use the compiler installed above or any other version of Visual Studio.
Try running the test suite (see Installing other useful packages below) after the installation to make sure everything is working as expected.
Development install
When you encounter a problem in Brian, we will sometimes ask you to install Brian’s latest development version, which includes changes that were included after its last release.
We regularly upload the latest development version of Brian to PyPI’s test server. You can install it via:
python -m pip install --upgrade --pre -i https://test.pypi.org/simple/ Brian2
Note that this requires that you already have all of Brian’s dependencies installed.
If you have git
installed, you can also install directly from github:
python -m pip install git+https://github.com/brian-team/brian2.git
Finally, in particular if you want to either contribute to Brian’s development or regularly test
its latest development version, you can directly clone the git repository at github
(https://github.com/brian-team/brian2) and then run pip install -e .
, to install
Brian in “development mode”. With this installation, updating the git repository is in
general enough to keep up with changes in the code, i.e. it is not necessary to install
it again.
Installing other useful packages
There are various packages that are useful but not necessary for working with Brian. These include: matplotlib (for plotting), pytest (for running the test suite), ipython and jupyter-notebook (for an interactive console).
conda install matplotlib pytest ipython notebook
python -m pip install matplotlib pytest ipython notebook
You should also have a look at the brian2tools package, which contains several useful functions to visualize Brian 2 simulations and recordings.
As of now, brian2tools
is not yet included in the conda-forge
channel, you therefore have to install it from our own brian-team
channel:
conda install -c brian-team brian2tools
python -m pip install brian2tools
Testing Brian
If you have the pytest testing utility installed, you can run Brian’s test suite:
import brian2
brian2.test()
It should end with “OK”, showing a number of skipped tests but no errors or failures. For more control about the tests that are run see the developer documentation on testing.