AttributeError on VSCode, Mac

Description of problem

I was trying to model a simple group of 3 neurons with a sinusoidal input current, based on the example from the brian2 documentation. I’m using Visual Studio Code (version 1.91.1) on a Mac (Sonoma 14.6.1). I get an AttributeError as soon as I try to do this (add an expression for the input current), while networks with no input run just fine. The same code works on Google Colab.

Minimal code to reproduce problem

import numpy as np
import matplotlib.pyplot as plt
from brian2 import *

start_scope()

G = NeuronGroup(3, '''dv/dt = (-v + I)/(10*ms) : 1
                        rates : Hz  # each neuron's input has a different rate
                        size : 1  # and a different amplitude
                        I = size*sin(2*pi*rates*t) : 1''')
G.rates = '10*Hz + i*Hz'
G.size = '(100-i)/100. + 0.1'

m = StateMonitor(G, ('v'), record=True)

net = Network(G)
net.add(m)

net.run(3*second)

m.v

What you have aready tried

Updating brian2.

Expected output (if relevant)

The code should return an array like this:

array([[ 0.00000000e+00, 0.00000000e+00, 6.91145836e-05, …,
-5.11718061e-01, -5.06808213e-01, -5.01878357e-01],
[ 0.00000000e+00, 0.00000000e+00, 7.53347921e-05, …,
-5.26665557e-01, -5.21624891e-01, -5.16559308e-01],
[ 0.00000000e+00, 0.00000000e+00, 8.14293100e-05, …,
-5.36499500e-01, -5.31378774e-01, -5.26227840e-01]])

This is what happens on Colab.

Actual output (if relevant)

(See error message below.)

Full traceback of error (if relevant)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:64 in render_node
return getattr(self, methname)(node)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:100 in render_Call
if node.func.id in self.auto_vectorise:

AttributeError: ‘Attribute’ object has no attribute ‘id’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File ~/Library/Python/3.9/lib/python/site-packages/IPython/core/interactiveshell.py:3550 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

Cell In[5], line 11
G.rates = ‘10Hz + iHz’

File ~/Library/Python/3.9/lib/python/site-packages/brian2/groups/neurongroup.py:904 in setattr
Group.setattr(self, key, value, level=1)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/groups/group.py:457 in setattr
var.get_addressable_value_with_unit(name, self).set_item(

File ~/Library/Python/3.9/lib/python/site-packages/brian2/core/variables.py:976 in set_item
self.set_with_expression_conditional(

File ~/Library/Python/3.9/lib/python/site-packages/brian2/core/base.py:335 in device_override_decorated_function
return func(*args, **kwds)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/core/variables.py:1141 in set_with_expression_conditional
codeobj = create_runner_codeobj(

File ~/Library/Python/3.9/lib/python/site-packages/brian2/codegen/codeobject.py:484 in create_runner_codeobj
return device.code_object(

File ~/Library/Python/3.9/lib/python/site-packages/brian2/devices/device.py:324 in code_object
scalar_code, vector_code, kwds = generator.translate(

File ~/Library/Python/3.9/lib/python/site-packages/brian2/codegen/generators/base.py:303 in translate
translated = self.translate_statement_sequence(

File ~/Library/Python/3.9/lib/python/site-packages/brian2/codegen/generators/base.py:142 in translate_statement_sequence
scalar_code[name] = self.translate_one_statement_sequence(

File ~/Library/Python/3.9/lib/python/site-packages/brian2/codegen/generators/numpy_generator.py:319 in translate_one_statement_sequence
line = self.translate_statement(stmt)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/codegen/generators/numpy_generator.py:73 in translate_statement
code = f"{var} {op} {self.translate_expression(expr)}"

File ~/Library/Python/3.9/lib/python/site-packages/brian2/codegen/generators/numpy_generator.py:38 in translate_expression
NumpyNodeRenderer(auto_vectorise=self.auto_vectorise)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:58 in render_expr
return self.render_node(node.body)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:64 in render_node
return getattr(self, methname)(node)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:147 in render_BinOp
return self.render_BinOp_parentheses(node.left, node.right, node.op)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:141 in render_BinOp_parentheses
f"{self.render_element_parentheses(left)} "

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:118 in render_element_parentheses
return self.render_node(node)

File ~/Library/Python/3.9/lib/python/site-packages/brian2/parsing/rendering.py:78 in render_node
raise SyntaxError(

File
SyntaxError: Brian equations/expressions do not support the ‘Call’ syntax.

Hi @lpiovano. Thank you for the clear and detailed report. The issue is most likely an incompatibility with Python 3.9, which we no longer support in Brian. The last version that still supported Python 3.9 was Brian 2.6 – you’d either have to use that version of Brian or upgrade your Python version.

Thank you for the swift response! After trying different python versions, I found that 3.11 solved the issue. It should be noted for anyone having the same problem, though, that any python 3.12+ won’t work due to the removal of distutils.

Could you give more details about why you think this is the case? Which version of Brian are you using? The latest Brian version (2.9.0) works with all Python versions ≥3.11 (for 3.14, we do not yet have a stable release with wheel files, but it can be installed from source).

I was trying to use 2.9 with python 3.14 in a virtual environment but ended up being unable to install the distutils package (which was required by some brian2 functions). After looking into it, I read that distutils was removed in 3.12 so I assumed I had the same problem. Perhaps it’s something else specific to VSCode, macOS or my venv (made with uv)?

The situation with distutils is a bit confusing: Brian does import distutils in a few places, but it doesn’t need the distutils package – instead, it depends on setuptools, which distributes a patched version of distutils (9. API Reference - setuptools 80.9.0 documentation). Did your virtual environment have setuptools installed ? I am on Linux, but for me uv venv --python 3.14, activating the venv and then using uv pip install brian2 worked, and Brian ran without issues.