Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental'

I am having problems trying to run TensorFlow on my Windows 10 machine. Code runs fine on my MacOS machine.

Traceback (most recent call last):
  File "c:\Users\Fynn\Documents\GitHub\AlpacaTradingBot\ai.py", line 15, in <module>
    from keras.models import Sequential, load_model
  File "C:\Users\Fynn\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\__init__.py", line 24, in <module>
    from keras import models
  File "C:\Users\Fynn\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\models\__init__.py", line 18, in <module>
    from keras.engine.functional import Functional
  File "C:\Users\Fynn\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\engine\functional.py", line 24, in <module>
    from keras.dtensor import layout_map as layout_map_lib
  File "C:\Users\Fynn\AppData\Local\Programs\Python\Python39\lib\site-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' from 'tensorflow.compat.v2.experimental' (C:\Users\Fynn\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\v2\experimental\__init__.py)
like image 811
Fynn Avatar asked Nov 19 '25 13:11

Fynn


1 Answers

This can be caused by an incompatibility between your tensorflow and your keras versions. In particular I see this with tensorflow==2.6.0 and keras==2.9.0, though I would not be surprised if other versions can cause this as well.

Either update your tensorflow version by:

pip install tensorflow==2.8

or downgrade your keras version by:

pip install keras==2.6
like image 185
Jesper Nielsen Avatar answered Nov 22 '25 03:11

Jesper Nielsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!