Python 属性错误:模块';mnist&x27;没有属性';列车图像';
我正在从freecodecamp.org复制视频 老师正在使用colab.research。他的代码如下:Python 属性错误:模块';mnist&x27;没有属性';列车图像';,python,attributeerror,mnist,Python,Attributeerror,Mnist,我正在从freecodecamp.org复制视频 老师正在使用colab.research。他的代码如下: !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 # trai
!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()
当他这样做的时候,一点问题都没有。但我收到以下错误消息:
---------------------------------------------------------------------------
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'
属性错误
如果你有问题
AttributeError: module 'mnist' has no attribute 'train_images'
raise EOFError("Compressed file ended before the " EOFError:
Compressed file ended before the end-of-stream marker was reached
然后您有另一个文件mnist.py
,它导入它而不是模块mnist
您可以检查导入的文件
import mnist
print( mnist.__file__ )
您可以在编辑器中打开此文件以检查此文件中的内容
或者,您甚至可以使用
print( open(mnist.__file__).read() )
若要解决此问题,必须重命名此文件
EOR或HTTP错误503 如果你有问题
AttributeError: module 'mnist' has no attribute 'train_images'
raise EOFError("Compressed file ended before the " EOFError:
Compressed file ended before the end-of-stream marker was reached
或
然后问题可能是服务器,然后您可以尝试从其他地方下载它
使用谷歌,我在PyTorch论坛
如果更改mnist.datasets\u url
,则可以从其他位置下载
#!pip install mnist
import mnist
mnist.datasets_url = 'https://ossci-datasets.s3.amazonaws.com/mnist/'
# training variables
x_train = mnist.train_images()
y_train = mnist.train_labels()
print('x_train:', x_train.shape)
print('y_train:', y_train.shape)
这对我来说在本地计算机和
googlecolab
中非常有用,它很可能是您的python环境。您使用的是什么虚拟环境?如果您正在使用conda,请在安装依赖项之前尝试创建一个新的虚拟环境。如果您使用的是venv
,请尝试同样的操作。谢谢您的回答,我认为我没有使用任何虚拟环境。我甚至不知道那件事。但奇怪的是,正因为如此,这很可能就是它抛出这些错误的原因。在未激活虚拟环境的情况下,不应安装依赖项,如mnist
、sklearn
等。否则,事情会变得一团糟。寻找如何在python中使用venv
。即使在环境中也是一样的问题。但至少它应该与colab.research合作。不幸的是,它不起作用。您是否复制并粘贴了上面的代码?对你有用吗?这有用吗?