doesn't work in pycharm

following code:

import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

num_epoch = 4
batch_size = 4
learning_rate = 0.001

transform = transforms.Compose(
     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]

train_dataset = torchvision.datasets.CIFAR10(root='./data', train=True, transform=transform)
test_dataset = torchvision.datasets.CIFAR10(root='./data', train=False, transform=transform)
train_loader =, batch_size=batch_size,shuffle=False)
test_loader =, batch_size=batch_size, shuffle=True)

Error that I got:

Cannot find reference ‘data’ in ' (ln 22 & 23)

It is better to show the traceback verbatim instead of picking just a part of it.

The problem should not be in Pycharm or does it work when you run the script directly?

I would check the installation directory of the torch package to see if it contains torch/utils/data. How to get the directory?

For the import package:

$ python3 -c 'import requests; print(requests.__file__)'

For the installation package:

$ python3 -m pip list -v | grep requests
requests               2.25.1          /usr/lib/python3/dist-packages