ImportError: No module named 'torchvision.datasets.mnist'
11,168
If you're using anaconda distribution, first install torchvision using:
$ conda install -c conda-forge torchvision
If the package is not installed, then it will be installed. Else, it will throw the message
# All requested packages already installed.
After this, try to import the torchvision.datasets
as you mentioned.
In [1]: from torchvision import datasets
In [2]: dir(datasets)
Out[2]:
['CIFAR10',
'CIFAR100',
'CocoCaptions',
'CocoDetection',
'DatasetFolder',
'EMNIST',
'FakeData',
'FashionMNIST',
'ImageFolder',
'LSUN',
'LSUNClass',
'MNIST',
'Omniglot',
'PhotoTour',
'SEMEION',
'STL10',
'SVHN',
....,
....
]
As you can see from above listing of dir(datasets)
, the dataset class for MNIST
is listed which will be the case when the torchvision package is installed correctly.
Related videos on Youtube
Author by
Nehal Ahuja
Updated on June 04, 2022Comments
-
Nehal Ahuja almost 2 years
Even after installing pytorch, this error is coming for this line.
from torchvision import datasets
-
kHarshit over 5 yearsJust to confirm, did you install
torchvision
as well?pip3 install torchvision
-
Monster over 5 yearsTry reinstalling torchvision with
pip install --upgrade --force-reinstall torchvision
-
-
dennlinger over 5 yearsFor any other distribution (not Anaconda), the PyTorch homepage provides a convenient tool that lets you input your environment, and return a command to install the relevant package, if you just scroll down a little bit.