Pycharm tensorflow2.3.1无法导入mnist数据集,程序运行报错No module named tensorflow.examples.tutorials.mnist
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets ( 'E:/pythonProject/python37/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data', one_hot=True)
报错原因是因为tensorflow2.3.1没有tutorials 文件 首先需要下载
tutorials下载链接:
tutorials
将下载好的文件解压到tensorflow/examples
如果原先有数据集的先卸载掉,因为这个代码会自动帮你下载,原先有数据集的运行就会报错。
运行代码:
结果如图
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting E:/pythonProject/python37/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data\train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting E:/pythonProject/python37/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data\train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting E:/pythonProject/python37/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data\t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting E:/pythonProject/python37/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data\t10k-labels-idx1-ubyte.gz