15

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)
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Fynn
  • 167
  • 1
  • 1
  • 5

4 Answers4

36

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
Jesper Nielsen
  • 401
  • 3
  • 4
  • pip install tensorflow==2.8 will update keras unfortunately. – jtb Jun 22 '22 at 16:09
  • Yes upgrading my tensorflow to 2.8 fixed my wrapt and dtensor error, pip install tensorflow==2.8 this worked, thanks! – Salih Osman Jul 07 '22 at 16:24
  • 2
    After a fresh installation of tensorflow 2.6.0 (on a Windows machine), using Keras 2.6 as suggested worked for me, simply by using `pip install keras==2.6` – Peter Jul 16 '22 at 12:37
  • thanks I've been been stuck in this for a while. waymo open dataset strictly depends on tf 2.6 and that causes quite a lot package conflicts. – Tim Wu Aug 13 '22 at 00:05
1

Just run :

pip install --disable-pip-version-check --no-cache-dir tensorflow
0

I tried many solutions to no avail, in the end this worked for me!

pip3 uninstall tensorflow absl-py astunparse flatbuffers gast google-pasta grpcio h5py keras keras-preprocessing libclang numpy opt-einsum protobuf setuptools six tensorboard tensorflow-io-gcs-filesystem termcolor tf-estimator-nightly typing-extensions wrapt
pip3 install --disable-pip-version-check --no-cache-dir tensorflow
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Fynn
  • 167
  • 1
  • 1
  • 5
0

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