Module 'torchvision' has no attribute 'datasets'

AlbertZhang: <p>Hi, I’m encountering an error that <code>module 'torchvision' has no attribute 'datasets'</code> when I’m trying to run <a href="https://github.com/junyuseu/pytorch-cifar-models" rel="nofollow noopener">pytorch-cifar</a>  today. But when I run it a few days ago, it worked.<br>
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 <code>0.3.1</code>.</p>
<p>Thanks for your help.</p>

smth: <p>do you have a folder in your current working directory called <code>torchvision</code> that is getting loaded instead of the global package <code>torchvision</code>?</p>

AlbertZhang: <p><a class="mention" href="/u/smth">@smth</a> 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. <img src="https://discuss.pytorch.org/images/emoji/apple/sweat_smile.png?v=5" title=":sweat_smile:" class="emoji" alt=":sweat_smile:"></p>

jingyu_han: <pre><code class="lang-auto">Traceback (most recent call last):
  File "tools/train_net.py", line 17, in &lt;module&gt;
    from core.data import make_data_loader
  File "./core/data/__init__.py", line 2, in &lt;module&gt;
    from .build import make_data_loader
  File "./core/data/build.py", line 10, in &lt;module&gt;
    from core.data import Datasets as D 
  File "./core/data/Datasets/__init__.py", line 2, in &lt;module&gt;
    from .coco import COCODataset
  File "./core/data/Datasets/coco.py", line 29, in &lt;module&gt;
    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.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; print(torch.__version__)
1.4.0
&gt;&gt;&gt; import torchvision
&gt;&gt;&gt; print(torchvision.__version__)
0.5.0
&gt;&gt;&gt;
</code></pre>
<p>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.  <a class="mention" href="/u/smth">@smth</a></p>

ptrblck: <p>Are you able to run these lines of code:</p>
<pre><code class="lang-python">import torchvision
import torchvision.datasets as datasets
</code></pre>
<p>If so, the error might come from the <code>COCODataset</code>, although I don’t see any obvious reasons for this error.</p>

jingyu_han: <p>after excuting your given command, here is my output:<br>
<code>No module named 'torchvision.datasets'; 'torchvision' is not a package</code><a class="mention" href="/u/ptrblck">@ptrblck</a></p>

ptrblck: <p>Could you create a new environment and install PyTorch as well as <code>torchvision</code> again?<br>
Something seems to be broken in your installation, when you are able to import <code>torchvision</code>, but not <code>torchvision.datasets</code>.</p>

jingyu_han: <p>Dear <a class="mention" href="/u/ptrblck">@ptrblck</a> I followed your instruction and create a new envs to test my code, unfortunately, the mentioned weird problem still exists. The same error for<code> torchvision.transforms</code></p>