我想开始学习一些机器学习,并尝试导入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
pip install tensorflow --upgrade
或者pip install tensorflow==2.9.1
(2.9.1 是目前最新版本)。如果你使用的是 GPU,那么你需要安装tensorflow-gpu
。然而,我看到你正在使用 Python 3.6,所以也许较新的 TensorFlow 版本与之不兼容。 - ClaudiaR