ModuleNotFoundError: No module named 'torchvision.transform' despite being installed

username: imharjyotbagga
cooked: <p>I have installed torchvision in anaconda, but despite that, I am getting an import error when importing it into my code.<br>
Here please note I have pytorch and torchvision installed on my system. But despite that, I am getting an import error while importing the module.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/3/337c3b85372aadb4facf57dad5520d37b5cb2172.png" data-download-href="https://discuss.pytorch.org/uploads/default/337c3b85372aadb4facf57dad5520d37b5cb2172" title="pyt"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/337c3b85372aadb4facf57dad5520d37b5cb2172_2_690x128.png" alt="pyt" data-base62-sha1="7lsw6O0lLC6XPBGP9nGRwDfKRuW" width="690" height="128" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/337c3b85372aadb4facf57dad5520d37b5cb2172_2_690x128.png, https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/337c3b85372aadb4facf57dad5520d37b5cb2172_2_1035x192.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/3/3/337c3b85372aadb4facf57dad5520d37b5cb2172_2_1380x256.png 2x" data-dominant-color="2B2F34"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">pyt</span><span class="informations">1718×321 67.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>The code for importing is given below, which is flashing the error.</p>
<pre><code class="lang-auto">import torchvision.datasets as datasets
import torchvision.transform as transforms
</code></pre>
<p>Please help me out with this error. Please note I don’t have a GPU, so have only installed the cpu version of pytorch using,<br>
<code>conda install pytorch torchvision cpuonly -c pytorch</code></p>
<p>Please help me sort out this issue.</p>

username: BTNug
cooked: <p>Hi <a class="mention" href="/u/imharjyotbagga">@imharjyotbagga</a>,<br>
I have several ways for you to check the issue:</p>
<ul>
<li>Open your terminal, then type the</li>
</ul>
<pre><code class="lang-auto">python -c "import sys; print(sys.path)"
</code></pre>
<ul>
<li>Check your site-package folder and make sure that datasets and transform folders are exists. (/home/gxuvimr/anaconda3/envs/pytorch/lib/python3.8/site-packages/torchvision</li>
<li>Please make sure that your site-package folder is listed in the sys.path.</li>
<li>Please also double check “_C.pyd” in the folder that I have just mentioned. Because in my past cases, import error is happening due to this file.</li>
</ul>
<p>Hope this helps in your debugging, thanks~</p>

username: imharjyotbagga
cooked: <p>Hey <a class="mention" href="/u/btnug">@BTNug</a>,<br>
Thanks for the prompt reply. I checked these packages and the above folder exists in my path.<br>
Also, I do have _C.so in the folder above, but not _C.pyd.<br>
Is it okay, or do I need to make any changes?</p>

username: BTNug
cooked: <p>Could you try to run this: <code>python -c "import torchvision"</code></p>
<p>If you couldn’t, it means that there is a path problem inside your packages. You could check the other threads here:</p>
<ul>
<li>(Provide issue+solution) <a href="https://github.com/pytorch/pytorch/issues/1376" rel="noopener nofollow ugc">https://github.com/pytorch/pytorch/issues/1376</a>
</li>
<li>(Provide &amp; Show issue+solution) <a href="https://www.programmersought.com/article/8096202170/" rel="noopener nofollow ugc">https://www.programmersought.com/article/8096202170/</a>
</li>
</ul>
<p>Hope this helps, cheers~</p>

username: ptrblck
cooked: <p>You have a typo in your code.<br>
Use <code>import torchvision.transforms as transforms</code> instead of <code>import torchvision.transform as transforms</code> (note the additional s).</p>
<p>PS: it’s better to post code snippets by wrapping them into three backticks ```, as it makes debugging easier. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: impratiksingh
cooked: <p>Starting in pytorch. Unable to find why there is a difference in behavior while doing import torchvision , in python vs ipython. I am getting the same module not found error in jupyter notebook even if the conda env installation was done correctly (using the command : conda install pytorch torchvision torchaudio cpuonly -c pytorch )</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/6/f6f0242606ddfb4e12c8f2af2f002ba2a82b2d14.png" data-download-href="https://discuss.pytorch.org/uploads/default/f6f0242606ddfb4e12c8f2af2f002ba2a82b2d14" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/f/6/f6f0242606ddfb4e12c8f2af2f002ba2a82b2d14.png" alt="image" data-base62-sha1="zevXo7YioufTqnyZ8Pxzu33obfS" width="690" height="406" data-dominant-color="131312"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">945×557 26.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: albanD
cooked: <p>Hi,</p>
<p>From the prompt, your <code>python</code> is version 3.8 and your ipython is based on 3.7. So they just point to two different implementations of python. And it seems that you have torchvision installed for the python 3.8 but not for the 3.7.</p>
<p>You can try to remove extra python installs to avoid such issues. Or use virtualenv that will make sure to have all of these consistent.</p>

username: M5klTig3r
cooked: <p>thanks! I had the same problem and this solved it <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=10" title=":grinning:" class="emoji" alt=":grinning:"><br>
I was quite sceptic though about “transform” <img src="https://discuss.pytorch.org/images/emoji/apple/joy.png?v=10" title=":joy:" class="emoji" alt=":joy:"></p>