Failed to load image Python extension: Could not find module

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.

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}")

Is it something I should worry about? How can I fix it?

4 Likes

How did you install torchvision? Did you build it from source or did you install the binaries? In any case, did you downgrade it recently?

I just used the command provided on PyTorch’s website. And that’s all I did, no downgrades.

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

Could you post an executable code snippet to reproduce the issue, please?

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.

Are you seeing the error while running import torchvision only?
If so, I can’t reproduce it using the same version:

pip list | grep vision
torchvision               0.11.2+cu102

>>> import torchvision
>>> torchvision.__version__
'0.11.2+cu102'
>>> 

Could you create a new virtual environment and reinstall torchvision there?

Yes. I created a new virtual environment and it still happens.

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.

>>> import torchvision
>>> torchvision.__version__
'0.11.2+cu113'
1 Like

Check once using

pip check torchvision
pip check torch

Hi,
I encountered the same problem, I am not using Cuda (running on Macbook M1 to test things).
Even when I run a basic script it happens:

import torch
import torchvision.io as io

ok = io.read_image("img.jpg")

torchvision version 0.10.0 (and on 0.11.2, I tried to see if a downgrade will fix it).
torch version is 1.10.1

Installed using pip

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.

Would really appreciate the help

2 Likes

exactly the same situation as @liranbd1 here.

EDIT: using python 3.9.9 installed via pyenv
EDIT2: downgrading to torchvision 0.10.0 didnt help
EDIT3: installing from python.org instead of brew/pyenv doesnt fix it either

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.

Hey,
I’m using windows and I encountered the same problem.
I’m using:

  • python: 3.9.7
  • torch: 1.10.1+cu102
  • torchvision: 0.11.2+cu102

EDIT
I’ve upgraded CUDA to 11.1 and everything is fine now. Still strange the error in CUDA 10.2

2 Likes

Hi. i have same problem too.

But i solved to downgrade torch and torchvision version.

My system is windows, and gtx 750ti using cuda 10.2.

I used

conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=10.2 -c pytorch

I think that latest version of pytorch isn’t match CUDA 10.2.

I hope that you solve this problem like this way.

Hi,
I faced the same problem on my MBA@M1 and downgrading of the torch and torchvision helped me.

pip install --upgrade torch==1.9.0
pip install --upgrade torchvision==0.10.0
12 Likes

Hi

I also have the same problem. I got the following warning when I import torchvision

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}")

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)

conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

When I call conda list, the following package shows up

torchvision               0.11.2               py38_cu102    pytorch
pytorch                    1.10.1               py3.8_cuda10.2_cudnn7_0    pytorch
pytorch-mutex             1.0                cuda    pytorch

Thank you for your help

Hi, I have the same problem.

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}")

My system is:
MacMini M1 macOS 12.1,
Python 3.9,
Pytorch 1.10.1,
torchvision 0.11.2

PyTorch and torchvision install by PIP.

Thanks for helping man, I was trying to solve this issue for about an hour

1 Like

I followed suggestion by Maxim to resolve the issue!
I downgraded from pytorch-1.10.2 and torchvision-0.11.3 to pytorch-1.9.0 and torchvision-0.10.0
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.
pip install --upgrade torch==1.9.0
pip install --upgrade torchvision==0.10.0
pip install --upgrade torchaudio==0.9.0

3 Likes

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