Reputation: 227
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)
Upvotes: 21
Views: 58235
Reputation: 227
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
Upvotes: 0
Reputation: 584
Just run :
pip install --disable-pip-version-check --no-cache-dir tensorflow
Upvotes: 1
Reputation: 460
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
Upvotes: 42
Reputation: 71
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
Upvotes: 0