Failed to load image Python extension: Could not find module

Davi_Magalhaes: <p>I was just training a model and this warning popped, I’ve never seen it before. I don’t know if it’s code related.</p>
<pre><code class="lang-auto">my_project\venv\lib\site-packages\torchvision\io\image.py:11: UserWarning: Failed to load image Python extension: Could not find module 'my_project\venv\Lib\site-packages\torchvision\image.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
  warn(f"Failed to load image Python extension: {e}")
</code></pre>
<p>Is it something I should worry about? How can I fix it?</p>

ptrblck: <p>How did you install <code>torchvision</code>? Did you build it from source or did you install the binaries? In any case, did you downgrade it recently?</p>

Davi_Magalhaes: <p>I just used the command provided on PyTorch’s website. And that’s all I did, no downgrades.</p>
<p><code>pip3 install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio===0.10.1+cu102 -f https://download.pytorch.org/whl/cu102/torch_stable.html</code></p>

ptrblck: <p>Could you post an executable code snippet to reproduce the issue, please?</p>

Davi_Magalhaes: <p>I was trying to find the problem doing some tests and I removed all torchvision references leaving only the import and it still appears. So I don’t think it’s code related.</p>

ptrblck: <p>Are you seeing the error while running <code>import torchvision</code> only?<br>
If so, I can’t reproduce it using the same version:</p>
<pre><code class="lang-python">pip list | grep vision
torchvision               0.11.2+cu102

&gt;&gt;&gt; import torchvision
&gt;&gt;&gt; torchvision.__version__
'0.11.2+cu102'
&gt;&gt;&gt; 
</code></pre>
<p>Could you create a new virtual environment and reinstall <code>torchvision</code> there?</p>

Davi_Magalhaes: <p>Yes. I created a new virtual environment and it still happens.</p>

Davi_Magalhaes: <p>I downloaded the version with CUDA 11.3 and it worked perfectly. I still have no idea what was wrong with my CUDA 10.2 version though.</p>
<pre><code class="lang-auto">&gt;&gt;&gt; import torchvision
&gt;&gt;&gt; torchvision.__version__
'0.11.2+cu113'
</code></pre>

Vidit_Agarwal: <p>Check once using</p>
<p>pip check torchvision<br>
pip check torch</p>

liranbd1: <p>Hi,<br>
I encountered the same problem, I am not using Cuda (running on Macbook M1 to test things).<br>
Even when I run a basic script it happens:</p>
<pre><code class="lang-auto">import torch
import torchvision.io as io

ok = io.read_image("img.jpg")
</code></pre>
<p>torchvision version 0.10.0 (and on 0.11.2, I tried to see if a downgrade will fix it).<br>
torch version is 1.10.1</p>
<p>Installed using pip</p>
<p>When I look at the Traceback it goes down to - op = torch._C._jit_get_operation(qualified_op_name) and then the error is thrown back up.</p>
<p>Would really appreciate the help</p>

pietz: <p>exactly the same situation as <a class="mention" href="/u/liranbd1">@liranbd1</a> here.</p>
<p>EDIT: using python 3.9.9 installed via pyenv<br>
EDIT2: downgrading to torchvision 0.10.0 didnt help<br>
EDIT3: installing from <a href="http://python.org" rel="noopener nofollow ugc">python.org</a> instead of brew/pyenv doesnt fix it either</p>

ptrblck: <p>This issue might be MAC-specific, as I couldn’t reproduce it on Linux and don’t have a MAC to test it, so feel free to create an issue on GitHub so that we could try to reproduce it.</p>

MohamedAteya: <p>Hey,<br>
I’m using windows and I  encountered the same problem.<br>
I’m using:</p>
<ul>
<li>python:  3.9.7</li>
<li>torch: 1.10.1+cu102</li>
<li>torchvision: 0.11.2+cu102</li>
</ul>
<p><strong>EDIT</strong><br>
I’ve upgraded CUDA to 11.1 and everything is fine now. Still strange the error in CUDA 10.2</p>

trio1245: <p>Hi. i have same problem too.</p>
<p>But i solved to downgrade torch and torchvision version.</p>
<p>My system is windows, and gtx 750ti using cuda 10.2.</p>
<p>I used</p>
<p>conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=10.2 -c pytorch</p>
<p>I think that latest version of pytorch isn’t match CUDA 10.2.</p>
<p>I hope that you solve this problem like this way.</p>

volkov-maxim: <p>Hi,<br>
I faced the same problem on my MBA@M1 and downgrading of the torch and torchvision helped me.</p>
<pre><code class="lang-auto">pip install --upgrade torch==1.9.0
pip install --upgrade torchvision==0.10.0
</code></pre>

Sureerat_Reaungamorn: <p>Hi</p>
<p>I also have the same problem. I got the following warning when I import torchvision</p>
<pre><code class="lang-auto">C:\ProgramData\Anaconda3\envs\torch1.10.1\lib\site-packages\torchvision\io\image.py:11: UserWarning: Failed to load image Python extension: Could not find module 'C:\ProgramData\Anaconda3\envs\torch1.10.1\Lib\site-packages\torchvision\image.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
  warn(f"Failed to load image Python extension: {e}")
</code></pre>
<p>My system is Windows 10 with CUDA 10.2. Pytorch 1.10.1 was install in a conda environment with python 3.8 using the following command (from pytorch website)</p>
<pre><code class="lang-auto">conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
</code></pre>
<p>When I call <code>conda list</code>, the following package shows up</p>
<pre><code class="lang-auto">torchvision               0.11.2               py38_cu102    pytorch
pytorch                    1.10.1               py3.8_cuda10.2_cudnn7_0    pytorch
pytorch-mutex             1.0                cuda    pytorch
</code></pre>
<p>Thank you for your help</p>

leonekwolfik: <p>Hi, I have the same problem.</p>
<pre><code class="lang-python">import torch
import torchvision.io as io
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/torchvision/io/image.py:11: UserWarning: Failed to load image Python extension: 
  warn(f"Failed to load image Python extension: {e}")
</code></pre>
<p>My system is:<br>
MacMini M1 macOS 12.1,<br>
Python 3.9,<br>
Pytorch 1.10.1,<br>
torchvision 0.11.2</p>
<p>PyTorch and torchvision install by PIP.</p>

Mukilan-Krishnakumar: <p>Thanks for helping man, I was trying to solve this issue for about an hour</p>

srichakra: <p>I followed suggestion by Maxim to resolve the issue!<br>
I downgraded from pytorch-1.10.2 and torchvision-0.11.3 to pytorch-1.9.0 and torchvision-0.10.0<br>
to resolve the error. Also, I am using pip in anaconda and the current pip dependency resolver doesn’t account for all the packages installed. I had to manually downgrade torchaudio to version 0.9.0 to avoid issues with it.<br>
<strong>pip</strong> install --upgrade torch==<strong>1.9.0</strong><br>
<strong>pip</strong> install --upgrade torchvision==<strong>0.10.0</strong><br>
<strong>pip</strong> install --upgrade torchaudio==<strong>0.9.0</strong></p>

Sana_Hobeichi: <p>I had exactly the same specs as you. I solved this issue by creating a new environment in Anaconda and installing the following versions<br>
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch</p>