'ImportError: cannot import name 'dtensor'

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

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/__init__.py", line 12, in <module>
        from keras import __version__
      File "/usr/local/lib/python3.6/dist-packages/keras/__init__.py", line 24, in <module>
        from keras import models
      File "/usr/local/lib/python3.6/dist-packages/keras/models/__init__.py", line 18, in <module>
        from keras.engine.functional import Functional
      File "/usr/local/lib/python3.6/dist-packages/keras/engine/functional.py", line 24, in <module>
        from keras.dtensor import layout_map as layout_map_lib
      File "/usr/local/lib/python3.6/dist-packages/keras/dtensor/__init__.py", 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'
>>>

I would appreciate any help! [1]: https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform/index.html



Solution 1:[1]

try sudo pip3 uninstall keras, apparently version 2.9.0rc2 has errors, then pip3 install keras==2.7.0rc2, check compatibility, https://libraries.io/pypi/keras/2.9.0rc2, I don't know if this is the definitive solution for jetpack 4.6.1

Solution 2:[2]

Before you must delete tensorflow and keras folder at site-package. Open admin command prompt use this codes

pip uninstall tensorflow 

pip install tensorflow --ignore-installed

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2