Import error while using tensorflow to import LSTM model


I have started dabbling with ML/DL and I am trying to import the LSTM model using the following code :

from tensorflow.keras.layers import LSTM

However, I am getting the following traceback error and am unsure how to proceed.

C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\python.exe C:/Users/Ahmed_Abdelmuniem/PycharmProjects/pythonProject/
2021-08-19 10:42:59.820385: W tensorflow/stream_executor/platform/default/] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-08-19 10:42:59.821236: I tensorflow/stream_executor/cuda/] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "C:\Users\Ahmed_Abdelmuniem\PycharmProjects\pythonProject\", line 1, in <module>
    from tensorflow.keras.layers import LSTM
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\", line 55, in <module>
    from ._api.v2 import compat
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\", line 39, in <module>
    from . import v1
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\v1\", line 34, in <module>
    from . import compat
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\v1\compat\", line 39, in <module>
    from . import v1
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\v1\compat\v1\", line 36, in <module>
    from tensorflow._api.v2.compat.v1 import data
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\v1\data\", line 13, in <module>
    from . import experimental
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\v1\data\experimental\", line 86, in <module>
    from . import service
  File "C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\compat\v1\data\experimental\service\", line 363, in <module>
    from import ShardingPolicy
ImportError: cannot import name 'ShardingPolicy' from '' (C:\Users\Ahmed_Abdelmuniem\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data\experimental\ops\

Process finished with exit code 1

I’m sure it doesn’t need to be said, but I am very new to tensorflow and still a beginner at python.


Alright, the solution turned out to be a re-installation with admin rights, as it seems certain parts didn’t install properly as without admin access pip didn’t have the right to edit certain folders.

Answered By – Ahmed

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published