Import NengoDL in Google Colab

Hello, I’m trying to follow spiking MNIST tutorial using Colab. [Colab code]

I added a code cell at the beginning to install Nengo&NengoDL,

!pip install nengo
!pip install nengo-dl

then tried to import some libraries.

%matplotlib inline

from urllib.request import urlretrieve

import nengo
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

import nengo_dl

But an error occurred at import nengo_dl.

ImportError                               Traceback (most recent call last)
<ipython-input-8-01afe5e72f23> in <module>()
      8 import matplotlib.pyplot as plt
---> 10 import nengo_dl

/usr/local/lib/python3.6/dist-packages/nengo_dl/ in <module>()
     57 # import into top-level namespace
---> 58 from nengo_dl import callbacks, compat, converter, dists, losses
     59 from nengo_dl.config import configure_settings
     60 from nengo_dl.converter import Converter

/usr/local/lib/python3.6/dist-packages/nengo_dl/ in <module>()
     18 from tensorflow.python.eager import context
---> 20 from nengo_dl import compat, utils

/usr/local/lib/python3.6/dist-packages/nengo_dl/ in <module>()
     12 import tensorflow as tf
     13 from tensorflow.python.keras import backend
---> 14 from tensorflow.python.keras.engine import network
     16 # TensorFlow compatibility

ImportError: cannot import name 'network'

Is there anything I have to know when running NengoDL project in Colab?
It seems to be okay when NengoDL is imported in local environment.
(using Anaconda, Python 3.7.7, TensorFlow 2.1.0, Nengo 3.0.0, NengoDL 3.2.0)

Colab probably uses the latest TensorFlow 2.3.0 as default and NengoDL has not yet been updated to support the changes that were introduced (see

Until NengoDL is updated, a workaround is to:

  • add this cell to your imports:

!git clone
!pip install -e ./nengo-dl

  • Restart the runtime

  • Run this cell:

import nengo_dl

I tested it and it works.


Thank you for your kind answer!
As another workaround, I downgraded TensorFlow to 2.1.0 version, and it worked well :slightly_smiling_face:

1 Like

Just be aware that installing TensorFlow using pip on colab is discouraged as the version pulled doesn’t have all the optimisations that the default colab build has.

1 Like

This should be resolved now, as NengoDL 3.3.0 has just been released and is compatible with TF 2.3. :sunny: