# Error in Google Colab

**URL:** <https://brian.discourse.group/t/error-in-google-colab/1401>\
**Category:** Support\
**Created:** [18 February 2025 12:24 UTC](https://brian.discourse.group/t/error-in-google-colab/1401 "2025-02-18T12:24:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SaeedF36](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/saeedf36/32/831_2.png) [@SaeedF36](https://brian.discourse.group/u/SaeedF36)\
**Post date:** [18 February 2025 12:24 UTC](https://brian.discourse.group/t/error-in-google-colab/1401/1 "2025-02-18T12:24:16Z")

</div>

# Description of problem

I am trying to use Brian2 on Colab. It seems that it works fine but I keep getting the following error for almost every line of code. It seems this is a problem with the way that Colab internal debugging tools try to automatically retrieve a `shape` attribute from objects in Brian2.

# Minimal code to reproduce problem

tau = 10\*ms

eqs = ‘’’

dv/dt = (1-v)/tau : 1

‘’’

# What you have already tried

# Expected output (if relevant)

# Actual output (if relevant)

# Full traceback of error (if relevant)

ERROR:root:Unexpected exception finding object shape  
Traceback (most recent call last):  
File “/usr/local/lib/python3.11/dist-packages/google/colab/\_debugpy\_repr.py”, line 54, in get\_shape  
shape = getattr(obj, ‘shape’, None)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/usr/local/lib/python3.11/dist-packages/brian2/core/preferences.py”, line 226, in **getattr**  
return self[name]  
~~~~ ^^^^^^  
File “/usr/local/lib/python3.11/dist-packages/brian2/core/preferences.py”, line 173, in **getitem**  
return self.prefs[item]  
~~~~~~~~~~ ^^^^^^  
KeyError: ‘shape’

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [18 February 2025 16:47 UTC](https://brian.discourse.group/t/error-in-google-colab/1401/2 "2025-02-18T16:47:01Z")

</div>

Hi @SaeedF36. Thanks for letting us know! I understand where the error is coming from and it is arguably a bug on our side: if you access `prefs.shape`, i.e. a non-existing `shape` attribute of our preferences object, you’ll get a `KeyError` because we are translating `prefs.shape` into `prefs['shape']`, but it should actually raise an `AttributeError` to work with things like `getattr`.  
On the other hand, I am not able to reproduce this on Google Collab, if I do a `%pip install brian2` and then paste some Brian example, everything seems to be running fine without error. Do you have a simple example that I can run (or a Google Collab to share) that leads to this error? Thanks!

---

<div class="post-metadata">

**Author:** ![SaeedF36](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/saeedf36/32/831_2.png) [@SaeedF36](https://brian.discourse.group/u/SaeedF36)\
**Post date:** [10 March 2025 22:46 UTC](https://brian.discourse.group/t/error-in-google-colab/1401/3 "2025-03-10T22:46:33Z")

</div>

Hi Marcel, thank you for your quick reply. Here is an example of what I encounter. In this case, it gives me this error twice. With every run, one of the errors disappears which means after three runs, it is clear and no exception happens. Thanks!

```python
!pip install brian2
!pip install brian2tools

from brian2 import *

tau = 10*ms
eqs = '''
dv/dt = (1-v)/tau : 1
'''
G = NeuronGroup(1, eqs)
run(100*ms)

```

BTW, I installed it locally and it runs smoothly. Although I prefer using Colab.

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [11 March 2025 09:34 UTC](https://brian.discourse.group/t/error-in-google-colab/1401/4 "2025-03-11T09:34:56Z")

</div>

Thanks for the update. This was a bit of a head-scratcher, since I could again copy&paste your code and it ran without issues. But I figured out the reason : you either have the “Variable Inspector” open (the \{x\} button on the left-hand side), or have it configured with “Display values in code editor: While executing” (configuration on the bottom of the variable inspector. This then triggers Colab to try checking for the `shape` argument of every variable in the local namespace which leads to the error you see. As I said previously, this is something we should fix in Brian, but until then deactivating the variable inspector, or replacing the `from brian2 import *` by a more restricted import should make everything work.

Best  
Marcel

---

<div class="post-metadata">

**Author:** ![SaeedF36](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/saeedf36/32/831_2.png) [@SaeedF36](https://brian.discourse.group/u/SaeedF36)\
**Post date:** [11 March 2025 10:57 UTC](https://brian.discourse.group/t/error-in-google-colab/1401/5 "2025-03-11T10:57:19Z")

</div>

Thank you so much! 🙏 You are absolutely right. When the inspector is open or it is configured to display numbers, it raises this error. Setting the configuration alone to ‘Never’ does not help and the inspector must be closed. Similarly, just closing the inspector while configuration is set to something other than ‘Never’ still gives the error. **So to get rid of the error, inspector must be closed and ‘Never’ have to be set for configuration.**
