无法在 Windows 上使用 python-mnist 包加载 MNIST 数据

Cannot load MNIST data with the python-mnist package on Windows

我通过 pip 在我的 Windows 设备上安装了 python-mnist 包,正如 Github 文档中所述,在我的 Anaconda 终端中输入以下命令:

pip install python-mnist

这对我来说效果很好。但是,当我尝试像这样使用此包加载数据时:

import mnist
train_images = mnist.train_images()

我收到以下错误

AttributeError: module 'mnist' has no attribute 'train_images'

我对在 python 中安装软件包还很陌生,我完全不知道为什么会这样。我一直在寻找 'mnist' 具有的其他属性,并发现通过转到 mnist.MNIST 我找到了一个名为 "train_images" 的模块。但是,将代码更改为

import mnist
mnist.MNIST.train_images()

还是报同样的错误。如果您能提供有关如何修复此错误的任何帮助,我将不胜感激。

如文档中所述,您首先需要从网上下载数据(那里的 4 个存档:http://yann.lecun.com/exdb/mnist/),然后 运行:

from mnist import MNIST
mndata = MNIST('./dir_with_mnist_data_files')
images, labels = mndata.load_training()