ImportError: cannot import name 'dtensor'

Hello Guys,

I just got a Jetson Nano and created my SD-Card with Jetpack 4.6.1. After that I installed TensorFlow like this:

Than I wanted to create an mnist Model but it seems like I cant import Keras? Any Idea ?

I just install Tensorflow and upgraded all apt-get packages.

>>> import tensorflow.keras
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/keras/api/_v2/keras/", line 12, in <module>
    from keras import __version__
  File "/usr/local/lib/python3.6/dist-packages/keras/", line 24, in <module>
    from keras import models
  File "/usr/local/lib/python3.6/dist-packages/keras/models/", line 18, in <module>
    from keras.engine.functional import Functional
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/", line 24, in <module>
    from keras.dtensor import layout_map as layout_map_lib
  File "/usr/local/lib/python3.6/dist-packages/keras/dtensor/", line 22, in <module>
    from tensorflow.compat.v2.experimental import dtensor as dtensor_api  # pylint: disable=g-import-not-at-top
ImportError: cannot import name 'dtensor'

This is the full Error log. I started python3 as sudo


Could you share how do you install the TensorFlow package?
We confirm that importing Keras with the l4t-tensorflow:r32.7.1-tf2.7-py3 container is working.

$ sudo docker run -it --rm --runtime nvidia --network host
root@nvidia-desktop:/# python3
Python 3.6.9 (default, Dec  8 2021, 21:08:43)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
>>> import tensorflow.keras


Could you share how do you install the TensorFlow package?

I first did a clean install of JetPack 4.6.1 and than I installed the dependencies exactly like the docs:

Before you install TensorFlow for Jetson, ensure you:

  1. Install JetPack on your Jetson device.
  2. Install system packages required by TensorFlow:

$ sudo apt-get update $ sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran

  1. Install and upgrade pip3.

$ sudo apt-get install python3-pip $ sudo pip3 install -U pip testresources setuptools==49.6.0

  1. Install the Python package dependencies.

$ sudo pip3 install -U --no-deps numpy==1.19.4 future==0.18.2 mock==3.0.5 keras_preprocessing==1.1.2 keras_applications==1.0.8 gast==0.4.0 protobuf pybind11 cython pkgconfig $ sudo env H5PY_SETUP_REQUIRES=0 pip3 install -U h5py==3.1.0

After that I install Tensorflow for Jetpack 4.6.1 like this:

sudo pip3 install --pre --extra-index-url Index of /compute/redist/jp/v461 tensorflow

Are there any performance drawbacks with using a docker and why do I have to install everything as sudo?

I used the docker now and that seems to work, but now I got a new problem. That can be seen here:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.