我试图开始学习一些机器学习,并尝试导入Tensorflow,但我得到了一个ModuleNotFoundError:
ModuleNotFoundError: No module named 'tensorflow.python.ops.numpy_ops'
当前的代码只是试图导入包:
import os
import sys
import math
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras import LSTM
完整的回溯是:
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版本: 3.6
Tensorflow版本: 2.6.2
发布于 2022-08-19 08:45:19
我不认为有tensorflow.keras.LSTM
。也许你在找tensorflow.keras.layers.LSTM
?
更新:
这个问题通过升级解决了最新版本的tensorflow (2.9.1)和python (3.9)。可以找到这里版本兼容性表。
https://stackoverflow.com/questions/73413744
复制相似问题