Module 'torchvision' has no attribute 'datasets'

Hi, I’m encountering an error that module 'torchvision' has no attribute 'datasets' when I’m trying to run pytorch-cifar today. But when I run it a few days ago, it worked.
I don’t know what is wrong with my pytorch. I tried to reinstall the torchvision and the running still ends up in failure. The version of pytorch on my computer is 0.3.1.

Thanks for your help.

do you have a folder in your current working directory called torchvision that is getting loaded instead of the global package torchvision?

@smth Thanks for your attention, smth. I installed multi versions of Pytorch by Annaconda and I strayed into a bad env where pytorch installation is uncompleted. Now I move to the correct env and no error occurs. Thanks again. :sweat_smile:

Traceback (most recent call last):
  File "tools/train_net.py", line 17, in <module>
    from core.data import make_data_loader
  File "./core/data/__init__.py", line 2, in <module>
    from .build import make_data_loader
  File "./core/data/build.py", line 10, in <module>
    from core.data import Datasets as D 
  File "./core/data/Datasets/__init__.py", line 2, in <module>
    from .coco import COCODataset
  File "./core/data/Datasets/coco.py", line 29, in <module>
    class COCODataset(torchvision.datasets.CocoDetection):
AttributeError: module 'torchvision' has no attribute 'datasets'
(embedmask) fei@yagi15:~/code/IDEstimation$ python
Python 3.7.6 (default, Jan  8 2020, 19:59:22) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
1.4.0
>>> import torchvision
>>> print(torchvision.__version__)
0.5.0
>>>

Hi, I got the same problem and don’t know how to solve it. I confirmed that my torch and torchvision packages have been installed competely. @smth

Are you able to run these lines of code:

import torchvision
import torchvision.datasets as datasets

If so, the error might come from the COCODataset, although I don’t see any obvious reasons for this error.

after excuting your given command, here is my output:
No module named 'torchvision.datasets'; 'torchvision' is not a package@ptrblck

Could you create a new environment and install PyTorch as well as torchvision again?
Something seems to be broken in your installation, when you are able to import torchvision, but not torchvision.datasets.

Dear @ptrblck I followed your instruction and create a new envs to test my code, unfortunately, the mentioned weird problem still exists. The same error for torchvision.transforms