ImportError: No module named examples.tutorials.mnist

ImportError: No module named examples.tutorials.mnist

我对这个错误感到非常沮丧,我所做的是从张量流教程中获取代码以导入 moist:

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

但是当我 运行 时 python 显示:

文件“/Users/kevinling/Desktop/Machine Learning/tensorflow.py”,第 2 行,在 从 tensorflow.examples.tutorials.mnist 导入 input_data 导入错误:没有名为 examples.tutorials.mnist

的模块

当我检查目录时,文件就在那里:

目录是:

enter image description here

input_data.py 就像:

The input_data.py

你已经安装tensorflow了吗?如果没有,请按照他们的 install instructions 或简单地使用 pip 安装:

pip install tensorflow

现在,请确保您当前 在 tensorflow 所在的文件夹中,然后尝试 运行 您的脚本。

python your_script.py

只需将您的示例从 "tensorflow.py" 重命名为其他名称即可。解释器正在尝试从您的脚本中导入必要的文件。