| 1 |
Importing Brian |
| 2 |
=============== |
| 3 |
|
| 4 |
After installation, Brian is available in the `brian2` package. By doing a |
| 5 |
wildcard import from this package, i.e.:: |
| 6 |
|
| 7 |
from brian2 import * |
| 8 |
|
| 9 |
you will not only get access to the ``brian2`` classes and functions, but also |
| 10 |
to everything in the ``pylab`` package, which includes the plotting functions |
| 11 |
from matplotlib_ and everything included in numpy/scipy (e.g. functions such |
| 12 |
as ``arange``, ``linspace``, etc.). Apart from this when you use the wildcard |
| 13 |
import, the builtin `input` function is overshadowed by the `input` module in the |
| 14 |
`brian2` package. If you wish to use the builtin `input` function in your program |
| 15 |
after importing the brian2 package then you can explicitly import the `input` function |
| 16 |
again as shown below:: |
| 17 |
|
| 18 |
from brian2 import * |
| 19 |
from builtins import input |
| 20 |
|
| 21 |
.. admonition:: The following topics are not essential for beginners. |
| 22 |
|
| 23 |
| |
| 24 |
|
| 25 |
Precise control over importing |
| 26 |
------------------------------ |
| 27 |
|
| 28 |
If you want to use a wildcard import from Brian, but don't want to import all |
| 29 |
the additional symbols provided by ``pylab`` or don't want to overshadow the |
| 30 |
builtin `input` function, you can use:: |
| 31 |
|
| 32 |
from brian2.only import * |
| 33 |
|
| 34 |
Note that whenever you use something different from the most general |
| 35 |
``from brian2 import *`` statement, you should be aware that Brian overwrites |
| 36 |
some numpy functions with their unit-aware equivalents |
| 37 |
(see :doc:`../developer/units`). If you combine multiple wildcard imports, the |
| 38 |
Brian import should therefore be the last import. Similarly, you should not |
| 39 |
import and call overwritten numpy functions directly, e.g. by using |
| 40 |
``import numpy as np`` followed by ``np.sin`` since this will not use the |
| 41 |
unit-aware versions. To make this easier, Brian provides a ``brian2.numpy_`` |
| 42 |
package that provides access to everything in numpy but overwrites certain |
| 43 |
functions. If you prefer to use prefixed names, the recommended way of doing |
| 44 |
the imports is therefore:: |
| 45 |
|
| 46 |
import brian2.numpy_ as np |
| 47 |
import brian2.only as br2 |
| 48 |
|
| 49 |
Note that it is safe to use e.g. ``np.sin`` and ``numpy.sin`` after a |
| 50 |
``from brian2 import *``. |
| 51 |
|
| 52 |
.. _matplotlib: http://matplotlib.org/ |
| 53 |
|
| 54 |
|
| 55 |
.. _dependency_checks: |
| 56 |
|
| 57 |
Dependency checks |
| 58 |
----------------- |
| 59 |
|
| 60 |
Brian2 relies on several Python packages (NumPy, SymPy, Jinja2, etc.) to function |
| 61 |
correctly. Modern Python package managers like pip and conda automatically ensure |
| 62 |
that compatible versions of these dependencies are installed when you install Brian2. |
| 63 |
|
| 64 |
**Recommended installation approach:** |
| 65 |
|
| 66 |
The safest way to ensure you have compatible dependencies is to install Brian2 |
| 67 |
using a package manager:: |
| 68 |
|
| 69 |
pip install brian2 |
| 70 |
|
| 71 |
or:: |
| 72 |
|
| 73 |
conda install -c conda-forge brian2 |
| 74 |
|
| 75 |
These commands will automatically install or upgrade dependencies to compatible |
| 76 |
versions. |
| 77 |
|
| 78 |
**If you encounter import errors:** |
| 79 |
|
| 80 |
If you see errors when importing Brian2, they typically indicate missing or |
| 81 |
incompatible dependencies. The error messages will usually tell you which |
| 82 |
package needs to be installed or updated. For example:: |
| 83 |
|
| 84 |
pip install --upgrade numpy |
| 85 |
|
| 86 |
**Legacy configurations:** |
| 87 |
|
| 88 |
Older versions of Brian2 included runtime dependency version checking controlled |
| 89 |
by the `core.outdated_dependency_error` preference. This feature has been |
| 90 |
removed in favor of relying on package managers for dependency resolution. |