Failed to load image Python extension: Could not find module

Hi,

I am getting something similar:

UserWarning: Failed to load image Python extension: dlopen(/Users/anderson/Library/Caches/pypoetry/virtualenvs/redacted-cMHZGf73-py3.9/lib/python3.9/site-packages/torchvision/image.so, 0x0006): Library not loaded: @rpath/libpng16.16.dylib
  Referenced from: /Users/anderson/Library/Caches/pypoetry/virtualenvs/redacted-cMHZGf73-py3.9/lib/python3.9/site-packages/torchvision/image.so
  Reason: tried: '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/usr/local/lib/libpng16.16.dylib' (no such file), '/usr/lib/libpng16.16.dylib' (no such file)
  warn(f"Failed to load image Python extension: {e}")

Seems like the file is not being included in torchvision-0.11.3-cp39-cp39-macosx_11_0_arm64.whl and we are not pointing to the right location anyway. I don’t have miniforge installed or a malfet user.

Hi Andersen!
I have 100% similar warning on MBP 14 m1 pro.
User/malfet/miniforge3/…
Do you know how to fix this warn? Internet doesn’t know same problems and I don’t know how to fix it.

1 Like

Same here with Macbook 16" M1Pro and python 3.8.9

1 Like

Getting the issue on Linux with torchvision nightly CPU (no CUDA) installed via:

conda install -c pytorch-nightly torchvision cpuonly

Message:
UserWarning: Failed to load image Python extension: /home/azureuser/miniconda3/envs/pytorch-0/lib/python3.9/site-packages/torchvision/image.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs

Demangling the symbol name, it becomes torch::jit::parseSchemaOrName(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)

Should I file a GitHub issue?

Hi Andrade, have you fixed it? I have the same problem.
There is a closed issue at https://github.com/pytorch/vision/issues/5137 where malfet said it has been resolved by 0.11.3, but I doubt that.
I create an issue at https://github.com/pytorch/vision/issues/5413.

1 Like

I solved it by installing libpng and libjpeg with Homebrew and manually adding symlinks to /usr/local/lib.

I still think we should address this with a ticket since PyTorch packages are supposed to come with all dependencies included.

Hey,
The same situation I encountered, I 'd like to wonder whether you have solved this error, plz.

Hey,
Hope everything is fine on your side :slight_smile:
I just upgraded my CUDA from 10.2 to 11.1 and everything worked.

I encountered the same problem and fixed it by going to the directory that is shown in the error. It opens up a .txt file and you just need to change the extension name of “image.py”. In my case, I had to change it to “image.jpg” since i am using jpg files for my code. Try it! hope it will help.

I’m getting this in a ubuntu docker image with 1.11, “pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113

I am having the same issue. I am installing from source in an ubuntu docker image with cuda 11.6. Torchvision v0.12.0

My issue was solved with conda install libpng jpeg

1 Like

On Apple M1Pro with latest pytorch nightly, this solved my issue

Same import warning here after building latest version from source on Ubuntu 20.04 (WSL2) Virtualenv with Intel CPU and Nvidia Turing.

Is there still not a known solution or cause of the problem? Same issue here on AMD CPU, Ampere GPU, Ubuntu 20.04, CUDA 11.4, and Anaconda Python 3.8, with torch (1.13.0a0+git6d6e04d) and torchvision (0.14.0a0+56fb841) compiled from source. None of the solutions mentioned here worked.

I’m seeing the same error on Windows 10 with Python 3.7, PyTorch 1.12.1 and torchvision 0.13.1. However, it looks like the warning message should be specifying the name of some extension, but it isn’t. Should I actually be concerned in this case?

Exact error message (with path to file shortened):
C:.…\lib\site-packages\torchvision\io\image.py:13: UserWarning: Failed to load image Python extension:
warn(f"Failed to load image Python extension: {e}")

I have the same issue, however only in one instance of two environments on Ubuntu 22.04. I installed two environments in parallel to work with lightning flash
The first package was installed through consecutive installation of

  1. Pytorch
  2. Pytorch Lightning
  3. Lightning Flash

The second one was installed through the default lightning flash install command for a conda package.
Weirdly enough, I get the error in only the package that was installed through the default lightning flash install command.
At first I got the error:

torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: /home/nico/miniconda3/envs/csuflash/lib/python3.10/site-packages/torchvision/image.so: undefined symbol: _ZN3c105ErrorC2ENS_14SourceLocationESs
  warn(f"Failed to load image Python extension: {e}")

I then tried to install the corresponding torchvision package for the cuda version that I have through running conda install torchvision=0.13.1=py310_cu116 -c pytorch

The error I get now is:

torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory
  warn(f"Failed to load image Python extension: {e}")

Hilariously enough, this environment features cudnn version 8.4.1.50.
The other environment (the one I installed consecutively), does NOT list cudnn in the package list, however, also doesn’t raise the aforementioned warning and also returns true on torch.cuda.is_available()

funky stuff

That’s interesting as it could mean that you are not installing any PyTorch binary which we build. We’ve bumped cuDNN from 8.3.2.44 to 8.5.0.96 and skipped 8.4, so check your install logs where this pip wheel or conda binary is coming from.

Interesting. My install procedure was that I always installed and then cloned so I could go revert to package status, should things fail, and then delete the second previous install (e.g. the default pytorch one…). In hindsight that was stupid, seeing as I could have just used revisions - which I am going to do from here on out.
Anyways: logs show that the lightning environment (which I still have, unlike the clean pytorch…), which was cloned from the pytorch does not have cudnn at all in it.
I’ll follow the install chain again, just to see what’s happening.
FYI: I use mamba instead of conda in a lot of cases, not sure if this has any influence.
FYI 2: I attempted the install with pytorch 1.12.1 and cuda 11.3.

Running mamba install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch (default install command from pytorch - only conda replaced by mamba) does not list cudnn in the packages to be installed.
Neither does conda