Pytorch DataLoader output is not iterable

I am following some tutorials online about Pytorch and it seems at some point I do not get the expected output although I follow everything step by step.

import torch
import torchvision
from torchvision import datasets, transforms
Train = datasets.MNIST("", train=True, download=True, transform=transforms.Compose([transforms.ToTensor()]))
Test = datasets.MNIST("", train=False, download=True, transform=transforms.Compose([transforms.ToTensor()]))
trainset = torch.utils.data.DataLoader(Train, batch_size= 10, shuffle=True)
testset = torch.utils.data.DataLoader(Test, batch_size= 10, shuffle=True)

But then when I try to loop through trainset I receive the following error:

    for ii in trainset:
        print(ii)
        break

    TypeError: __array__() takes 1 positional argument but 2 were given

Can anyone tell me why do I get this error and how I can fix it?

I am able to execute the code as it is, without any error.
I am not sure why you are facing this error. Perhaps the error is in any other line than this one?

Thank you. This is the entire code. Do you think I should downgrade or upgrade any package:
This is the list of packages installed in my environment:

argon2-cffi
async-generator
attrs
backcall
bleach
certifi==2021.5.30
cffi
colorama
debugpy==1.3.0
decorator
defusedxml
entrypoints==0.3
importlib-metadata
ipykernel==6.0.0
ipython==7.25.0
ipython-genutils
ipywidgets
jedi==0.18.0
Jinja2
joblib==1.0.1
jsonschema
jupyter
jupyter-client
jupyter-console
jupyter-core
jupyterlab-pygments
jupyterlab-widgets
MarkupSafe
matplotlib-inline==0.1.2
mistune
nbclient
nbconvert
nbformat
nest-asyncio
notebook
numpy==1.21.0
packaging
pandas==1.2.5
pandocfilters
parso==0.8.2
pickleshare
Pillow==8.3.0
prometheus-client
prompt-toolkit==3.0.19
pycparser
Pygments
pyparsing
pyrsistent
python-dateutil
pytz==2021.1
pywin32==301
pywinpty==1.1.3
pyzmq==22.1.0
qtconsole==5.1.1
QtPy==1.9.0
scikit-learn==0.24.2
scipy==1.7.0
Send2Trash==1.7.1
sip==4.19.13
six
sklearn==0.0
terminado==0.10.1
testpath
threadpoolctl==2.1.0
torch==1.9.0
torchaudio==0.9.0
torchvision==0.10.0
tornado
traitlets
typing-extensions==3.10.0.0
wcwidth
webencodings==0.5.1
widgetsnbextension
wincertstore==0.2
zipp

I do not see any suspicious packages that could cause this.
Do you have any other code in your file other than following lines?

import torch
import torchvision
from torchvision import datasets, transforms
Train = datasets.MNIST("", train=True, download=True, transform=transforms.Compose([transforms.ToTensor()]))
Test = datasets.MNIST("", train=False, download=True, transform=transforms.Compose([transforms.ToTensor()]))
trainset = torch.utils.data.DataLoader(Train, batch_size= 10, shuffle=True)
testset = torch.utils.data.DataLoader(Test, batch_size= 10, shuffle=True)

for ii in trainset:
    print(ii)
    break

You are most likely facing the PIL/Pillow issue as described here , which was breaking the numpy interaction in 8.3.0 and was already fixed in 8.3.1 after @tom’s fix was merged.