3

I am trying to start learning some Machine Learning and am trying to import Tensorflow but am getting a ModuleNotFoundError:

ModuleNotFoundError: No module named 'tensorflow.python.ops.numpy_ops'

The code currently just tries to import packages:

import os
import sys
import math
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras import LSTM

The full traceback is:

Traceback (most recent call last): 

 File "C:\Users\stacey\Documents\Atela\MachineLearning\NeuralNetworks\NeuralNetwork1.0.py", line 17, in <module>
    from tensorflow.keras import LSTM

  File "C:\Users\stacey\AppData\Roaming\Python\Python36\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util

  File "C:\Users\stacey\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\__init__.py", line 47, in <module>
    from tensorflow.python import distribute

  File "C:\Users\stacey\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\distribute\__init__.py", line 28, in <module>
    from tensorflow.python.distribute.experimental import collective_all_reduce_strategy

  File "C:\Users\stacey\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\distribute\experimental\__init__.py", line 25, in <module>
    from tensorflow.python.distribute import tpu_strategy

  File "C:\Users\stacey\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\distribute\tpu_strategy.py", line 28, in <module>
    from tensorflow.compiler.xla.experimental.xla_sharding import xla_sharding

  File "C:\Users\stacey\AppData\Roaming\Python\Python36\site-packages\tensorflow\compiler\xla\experimental\xla_sharding\xla_sharding.py", line 23, in <module>
    from tensorflow.compiler.tf2xla.python import xla as tf2xla

  File "C:\Users\stacey\AppData\Roaming\Python\Python36\site-packages\tensorflow\compiler\tf2xla\python\xla.py", line 43, in <module>
    from tensorflow.python.ops.numpy_ops import np_utils

ModuleNotFoundError: No module named 'tensorflow.python.ops.numpy_ops'

Python version: 3.6
Tensorflow version: 2.6.2

1 Answer 1

3

I don't think there is a tensorflow.keras.LSTM. Maybe you're looking for tensorflow.keras.layers.LSTM ?

Update:

The issue was solved by upgrading to the latest versions both tensorflow (2.9.1) and python (3.9). Here can be found a version compatibility table.

Sign up to request clarification or add additional context in comments.

6 Comments

I tried from keras.layers import LSTM but got the same error
Does this help ? Maybe you just have to upgrade tensorflow version stackoverflow.com/a/66203280/14774959
I uninstalled and reinstalled before posting the question - how do I make sure I have the latest version?
Yes, it looks like that with python 3.6, the maximum version of tensorflow that you can get is 2.6. If it's not a problem for you, you should consider also upgrading python tensorflow.org/install/source?hl=en#tested_build_configurations
Thanks @ClaudiaR - ended up removing python and all the packages and reinstalling everything with up to date versions which sorted the issue out
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.