You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

复现FreeCodeCamp教程代码时遇mnist模块AttributeError及Pycharm中EOFError问题求助

Troubleshooting MNIST Module Errors in Google Colab and PyCharm

I'm replicating the tutorial content from the FreeCodeCamp YouTube channel at the 2 hour 50 minute mark. The instructor ran the following code flawlessly in Google Colab:

!pip install pillow mnist numpy sklearn
from PIL import Image
import mnist
import numpy as np
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import confusion_matrix

# training variables
x_train = mnist.train_images()
y_train = mnist.train_labels()

But I'm running into two distinct issues depending on the environment:

Google Colab Error

When executing this code in Colab, I get an AttributeError:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-b693104c2566> in <module>()
      1 # training variables
----> 2 x_train = mnist.train_images()
AttributeError: module 'mnist' has no attribute 'train_images'

PyCharm Error

In PyCharm, the train_images() call doesn't throw an AttributeError, but instead hits an EOFError during data loading:

raise EOFError("Compressed file ended before the "
EOFError: Compressed file ended before the end-of-stream marker was reached

I've searched for solutions on Google and StackOverflow without success. As an additional check, I looked into the mnist module's __init__.py file and confirmed the train_images() function is indeed present:

def train_images():
    """Return train images from Yann LeCun MNIST database as a numpy array.
    Download the file, if not already found in the temporary directory of the system.
    Returns
    -------
    train_images : numpy.ndarray
        Numpy array with the images in the train MNIST database.
        The first dimension indexes each sample, while the other two index rows and columns of the image
    """
    return download_and_parse_mnist_file('train-images-idx3-ubyte.gz')

def test_images():
    """Return test images from Yann LeCun MNIST database as a numpy array.
    Download the file, if not already found in the temporary directory of the system.
    Returns
    -------
    test_images : numpy.ndarray
        Numpy array with the images in the train MNIST database.
        The first dimension indexes each sample, while the other two index rows and columns of the image
    """
    return download_and_parse_mnist_file('t10k-images-idx3-ubyte.gz')

I'm looking for technical solutions to fix both of these errors.

内容的提问来源于stack exchange,提问作者Osmose

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 16:12:32