Debian Codegraph @

docs_sphinx/introduction/install.rst

raw
1 Installation
2 ============
3
4 .. contents::
5 :local:
6 :depth: 1
7
8 There are various ways to install Brian, and we recommend that you chose the installation method that
9 they are most familiar with and use for other Python packages. If you do not yet have Python installed on
10 your system (in particular on Windows machines), you can install Python and all of Brian's dependencies
11 via the `Anaconda distribution <https://www.anaconda.com/distribution/#download-section>`_. You can then install
12 Brian with the ``conda`` package manager as detailed below.
13
14 .. note::
15 You need to have access to Python >=3.12 (see Brian's :ref:`support policy <supported_python>`). In particular,
16 Brian no longer supports Python 2 (the last version to support Python 2 was :ref:`brian2.3`). All provided
17 Python packages also require a 64 bit system, but every desktop or laptop machine built in the last 10 years (and
18 even most older machines) is 64 bit compatible.
19
20 If you are relying on Python packages for several, independent projects, we recommend that you make use
21 of separate environments for each project. In this way, you can safely update and install packages for
22 one of your projects without affecting the others. Both, ``conda`` and ``pip`` support installation in
23 environments -- for more explanations see the respective instructions below.
24
25 Standard install
26 ----------------
27
28 .. tabs::
29
30 .. group-tab:: conda package
31
32 We recommend installing Brian into a separate environment, see
33 `conda's documentation <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html>`_
34 for more details.
35 Brian 2 is not part of the main Anaconda distribution, but built using the community-maintained
36 `conda-forge <https://conda-forge.org/>`_ project. You will therefore have to to install it from the
37 `conda-forge channel <https://anaconda.org/conda-forge>`_. To do so, use::
38
39 conda install -c conda-forge brian2
40
41 You can also permanently add the channel to your list of channels::
42
43 conda config --add channels conda-forge
44
45 This has only to be done once. After that, you can install and update the brian2 packages as any other
46 Anaconda package::
47
48 conda install brian2
49
50
51 .. group-tab:: PyPI package (``pip``)
52
53 We recommend installing Brian into a separate "virtual environment", see the
54 `Python Packaging User Guide <https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_
55 for more information.
56 Brian is included in the PyPI package index: https://pypi.python.org/pypi/Brian2
57 You can therefore install it with the ``pip`` utility::
58
59 python -m pip install brian2
60
61 In rare cases where your current environment does not have access to the ``pip`` utility, you first
62 have to install ``pip`` via::
63
64 python -m ensurepip
65
66 .. group-tab:: Ubuntu/Debian package
67
68 If you are using a recent `Debian <https://debian.org>`_-based Linux distribution (Debian itself, or one if its
69 derivatives like `Ubuntu <https://ubuntu.com>`_ or `Linux Mint <https://linuxmint.com/>`_), you can install Brian
70 using its built-in package manager::
71
72 sudo apt install python3-brian
73
74 Brian releases get packaged by the `Debian Med <https://www.debian.org/devel/debian-med/>`_ team, but note that
75 it might take a while until the most recent version shows up in the repository.
76
77 .. group-tab:: Fedora package
78
79 If you are using `Fedora Linux <https://getfedora.org/>`_, you can install Brian using its built-in package
80 manager::
81
82 sudo dnf install python-brian2
83
84 Brian releases get packaged by the `NeuroFedora <https://docs.fedoraproject.org/en-US/neurofedora/overview/>`_ team,
85 but note that it might take a while until the most recent version shows up in the repository.
86
87 .. group-tab:: Spack package
88
89 `Spack <https://spack.io>`_ is a flexible package manager supporting multiple versions, configurations, platforms, and compilers.
90
91 After setting up Spack you can install Brian with the following command::
92
93 spack install py-brian2
94
95 .. _updating_install:
96
97 Updating an existing installation
98 ---------------------------------
99 How to update Brian to a new version depends on the installation method you used
100 previously. Typically, you can run the same command that you used for installation
101 (sometimes with an additional option to enforce an upgrade, if available):
102
103 .. tabs::
104
105 .. group-tab:: conda package
106
107 Depending on whether you added the ``conda-forge`` channel to the list of channels
108 or not (see above), you either have to include it in the update command again or
109 can leave it away. I.e. use::
110
111 conda update -c conda-forge brian2
112
113 if you did not add the channel, or::
114
115 conda update brian2
116
117 if you did.
118
119 .. group-tab:: PyPI package (``pip``)
120
121 Use the install command together with the ``--upgrade`` or ``-U`` option::
122
123 python -m pip install -U brian2
124
125 .. group-tab:: Ubuntu/Debian package
126
127 Update the package repository and ask for an install. Note that the package will
128 also be updated automatically with commands like ``sudo apt full-upgrade``::
129
130 sudo apt update
131 sudo apt install python3-brian
132
133 .. group-tab:: Fedora package
134
135 Update the package repository (not necessary in general, since it will be updated
136 regularly without asking for it), and ask for an update. Note that the package will
137 also be updated automatically with commands like ``sudo dnf upgrade``::
138
139 sudo dnf check-update python-brian2
140 sudo dnf upgrade python-brian2
141
142
143 .. _installation_cpp:
144
145 Requirements for C++ code generation
146 ------------------------------------
147
148 C++ code generation is highly recommended since it can drastically increase the
149 speed of simulations (see :doc:`../user/computation` for details). To use it,
150 you need a C++ compiler and Cython_ (automatically installed as a dependency
151 of Brian).
152
153 .. tabs::
154
155 .. tab:: Linux and OS X
156
157 On Linux and Mac OS X, the conda package will automatically install a C++ compiler.
158 But even if you install Brian in a different way, you will most likely already have a
159 working C++ compiler installed on your system (try calling ``g++ --version``
160 in a terminal). If not, use your distribution's package manager to install a ``g++`` package.
161
162 .. tab:: Windows
163
164 On Windows, :ref:`runtime` (i.e. Cython) requires the Visual Studio compiler, but you do not need a full Visual
165 Studio installation, installing the much smaller "Build Tools" package is sufficient:
166
167 * Install the `Microsoft Build Tools for Visual Studio <https://visualstudio.microsoft.com/visual-cpp-build-tools/>`_.
168 * In Build tools, install C++ build tools and ensure the latest versions of MSVCv... build tools and Windows 10 SDK are checked.
169 * Make sure that your ``setuptools`` package has at least version 34.4.0 (use ``conda update setuptools`` when
170 using Anaconda, or ``python -m pip install --upgrade setuptools`` when using pip).
171
172 For :ref:`cpp_standalone`, you can either use the compiler installed above or any other version of Visual Studio.
173
174 Try running the test suite (see :ref:`testing_brian` below) after the installation to make sure everything is working as expected.
175
176 .. _development_install:
177
178 Development install
179 -------------------
180 When you encounter a problem in Brian, we will sometimes ask you to install Brian's latest development version,
181 which includes changes that were included after its last release.
182
183 We regularly upload the latest development version of Brian to PyPI's test server. You can install it via::
184
185 python -m pip install --upgrade --pre -i https://test.pypi.org/simple/ Brian2
186
187 Note that this requires that you already have all of Brian's dependencies installed.
188
189 If you have ``git`` installed, you can also install directly from github::
190
191 python -m pip install git+https://github.com/brian-team/brian2.git
192
193 Finally, in particular if you want to either contribute to Brian's development or regularly test
194 its latest development version, you can directly clone the git repository at github
195 (https://github.com/brian-team/brian2) and then run ``pip install -e .``, to install
196 Brian in "development mode". With this installation, updating the git repository is in
197 general enough to keep up with changes in the code, i.e. it is not necessary to install
198 it again.
199
200 .. _testing_brian:
201
202 Installing other useful packages
203 --------------------------------
204 There are various packages that are useful but not necessary for working with
205 Brian. These include: matplotlib_ (for plotting), pytest_ (for running the test
206 suite), ipython_ and jupyter_-notebook (for an interactive console).
207
208 .. tabs::
209 .. group-tab:: conda package
210
211 ::
212
213 conda install matplotlib pytest ipython notebook
214
215 .. group-tab:: PyPI package (``pip``)
216
217 ::
218
219 python -m pip install matplotlib pytest ipython notebook
220
221 You should also have a look at the brian2tools_ package, which contains several
222 useful functions to visualize Brian 2 simulations and recordings.
223
224 .. tabs::
225 .. group-tab:: conda package
226
227 As of now, ``brian2tools`` is not yet included in the ``conda-forge``
228 channel, you therefore have to install it from our own ``brian-team`` channel::
229
230 conda install -c brian-team brian2tools
231
232 .. group-tab:: PyPI package (``pip``)
233
234 ::
235
236 python -m pip install brian2tools
237
238
239 Testing Brian
240 -------------
241
242 If you have the pytest_ testing utility installed, you can run Brian's test
243 suite::
244
245 import brian2
246 brian2.test()
247
248 It should end with "OK", showing a number of skipped tests but no errors or
249 failures. For more control about the tests that are run see the
250 :doc:`developer documentation on testing <../developer/guidelines/testing>`.
251
252 .. _matplotlib: http://matplotlib.org/
253 .. _ipython: http://ipython.org/
254 .. _jupyter: http://jupyter.org/
255 .. _brian2tools: https://brian2tools.readthedocs.io
256 .. _azure: https://azure.microsoft.com/en-us/services/devops/pipelines/
257 .. _pytest: https://docs.pytest.org/en/stable/
258 .. _Cython: http://cython.org/