Failed to load image Python extension: Could not find module

Ups. sorry I have checked the wrong environment here. My mistake and please accept my apologies for triple posting. cudnn 8.4.1 was part of the install coming from mamba install -c conda-forge lightning-flash so part of the flash installation.
However, I am still wondering why I have no cudnn package in the environments that I installed through pytorch’s commands

cuDNN and other libs are shipped directly in the binaries and are not listed as 3rd party dependencies. I don’t know what lighting-flash does with cuDNN but it seems as if different versions might be installed.
Once you’ve installed PyTorch you can check the cuDNN version via print(torch.backends.cudnn.version()) or python -m torch.utils.collect_env.

The environment i installed through flash directly shows: print(torch.backends.cudnn.version()) 8401
The environment installed from pytorch in subsequent steps shows: print(torch.backends.cudnn.version()) 8302

Could you post the install log for the flash install which might show which exact binary is installed?

I added pytest later on and a compatible cudatoolkit, so the dump is for the current status of the package. I ran the following commands:

~/miniconda3/bin/conda create --name csuflash
~/miniconda3/condabin/mamba install -c conda-forge lightning-flash
~/miniconda3/bin/conda install cudatoolkit=11.6 -c conda-forge
~/miniconda3/bin/conda install pytest -c conda-forge
~/miniconda3/bin/conda install torchvision=0.13.1=py310_cu116 -c pytorch

Unfortunately I am unable to find a command that shows me the build version for a specific revision. conda list -r only shows the version installed, neither the channel nor build.
The current status of the environment is as follows:

https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2022.9.24-ha878542_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.36.1-hea4e1c9_2.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libgfortran5-12.1.0-hdcd56e2_16.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-12.1.0-ha89aaad_16.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/tzdata-2022d-h191b570_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libgfortran-ng-12.1.0-h69a702a_16.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libgomp-12.1.0-h8d9b700_16.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-2_gnu.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-12.1.0-h8d9b700_16.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-h7f98852_4.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/c-ares-1.18.1-h7f98852_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/cudatoolkit-11.6.0-hecad31d_10.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libabseil-20220623.0-cxx17_h48a1fff_4.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libffi-3.4.2-h7f98852_5.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libnsl-2.0.0-h7f98852_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libopenblas-0.3.21-pthreads_h78a6416_3.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.32.1-h7f98852_1000.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.2.12-h166bdaf_3.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.3-h27087fc_1.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/ninja-1.11.0-h924138e_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/openssl-3.0.5-h166bdaf_2.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/re2-2022.06.01-h27087fc_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/sleef-3.5.1-h9b69904_2.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/xz-5.2.6-h166bdaf_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/yaml-0.2.5-h7f98852_2.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/cudnn-8.4.1.50-hed8a83a_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libblas-3.9.0-16_linux64_openblas.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libprotobuf-3.20.1-h6239696_4.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.39.3-h753d276_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/nccl-2.14.3.1-h0800d71_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/readline-8.1.2-h0f457ee_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.12-h27826a3_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/zlib-1.2.12-h166bdaf_3.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/grpc-cpp-1.48.1-hc2bec63_1.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/intel-openmp-2022.1.0-h9e868ea_3769.conda
https://conda.anaconda.org/conda-forge/linux-64/libcblas-3.9.0-16_linux64_openblas.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.9.0-16_linux64_openblas.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/python-3.10.6-ha86cf86_0_cpython.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/absl-py-1.2.0-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/attrs-22.1.0-pyh71513ae_1.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/blinker-1.4-py_1.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/cachetools-4.2.4-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/certifi-2022.9.24-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-2.1.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.5-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/fsspec-2022.8.2-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/idna-3.4-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/iniconfig-1.1.1-pyh9f0ad1d_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/magma-2.5.4-h6103c52_2.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/mkl-2022.1.0-hc2b9512_224.conda
https://conda.anaconda.org/conda-forge/noarch/py-1.11.0-pyh6c4a22f_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pyasn1-0.4.8-py_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pycparser-2.21-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pydeprecate-0.3.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pyjwt-2.5.0-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pyparsing-3.0.9-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/python_abi-3.10-2_cp310.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pytz-2022.2.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/tensorboard-plugin-wit-1.8.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/tomli-2.0.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.3.0-pyha770c72_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/wheel-0.37.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/zipp-3.8.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/cffi-1.15.1-py310h255011f_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/click-8.1.3-py310hff52083_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/frozenlist-1.3.1-py310h5764c6d_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/future-0.18.2-py310hff52083_5.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/importlib-metadata-4.11.4-py310hff52083_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/markupsafe-2.1.1-py310h5764c6d_1.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/multidict-6.0.2-py310h5764c6d_1.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/numpy-1.23.3-py310h53a5b5f_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/packaging-21.3-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/pluggy-1.0.0-py310hff52083_3.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pyasn1-modules-0.2.7-py_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/pysocks-1.7.1-py310hff52083_5.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.8.2-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pyu2f-0.1.5-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/pyyaml-6.0-py310h5764c6d_4.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/rsa-4.9-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/setuptools-59.5.0-py310hff52083_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/tqdm-4.64.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.3.0-hd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/aiosignal-1.2.0-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/async-timeout-4.0.2-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/brotlipy-0.7.0-py310h5764c6d_1004.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/cryptography-37.0.1-py310h9ce1e76_0.conda
https://conda.anaconda.org/conda-forge/linux-64/grpcio-1.48.1-py310h0547f17_1.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/jsonargparse-4.7.3-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/markdown-3.4.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/pandas-1.5.0-py310h769672d_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pip-22.2.2-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/protobuf-3.20.1-py310hd8f1fbe_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/pytest-7.1.3-py310hff52083_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/pytorch-1.12.1-cuda112py310h51fe464_200.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/werkzeug-2.2.2-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/yarl-1.7.2-py310h5764c6d_2.tar.bz2
https://conda.anaconda.org/conda-forge/linux-64/aiohttp-3.8.3-py310h5764c6d_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/oauthlib-3.2.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pyopenssl-22.0.0-pyhd8ed1ab_1.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/torchmetrics-0.9.3-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/urllib3-1.26.11-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/requests-2.28.1-pyhd8ed1ab_1.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/google-auth-1.35.0-pyh6c4a22f_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/requests-oauthlib-1.3.1-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/google-auth-oauthlib-0.4.6-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/tensorboard-2.4.1-pyhd8ed1ab_1.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pytorch-lightning-1.6.5-pyhd8ed1ab_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/lightning-flash-0.7.5-pyhd8ed1ab_0.tar.bz2

When installing torchvision with the following command on linux aarch64 with python3.10:

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu

The image.so library is missing in the dist-packages folder:

/usr/local/lib/python3.10/dist-packages/torchvision/

Resulting in the following warning when importing torchvision:

torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
  warn(f"Failed to load image Python extension: {e}")

When building torchvision from source the image.so file is at the right location and the import warning is gone. So probably the pip wheel is not created correctly.

2 Likes

Same deal as Sten_Geoes when installing on Jetson Jetpack 5.02 (aarch64). Building from source resolved the issue. I guess the wheel is missing a dependency, or assuming one exists that isn’t there.

can also confirm Sten_Geoes solution worked for me. 1/27/23, Pytorch Version 1.13.1 CPU, Torchvision 0.13.1a0. installed using pip. building from source revolved the failed to load image python extension error.

I resolved the same issue by reinstalling pytorch with:
pip3 install numpy --pre torch torchvision torchaudio --force-reinstall --index-url https://download.pytorch.org/whl/nightly/cu117

I have Ubuntu 22.04 , and the issue emerged after the following installs:
pip install “ray[tune]”
conda install torch-fidelity torchmetrics
pip install optuna

My guess for the quilty one is conda install torch-fidelity torchmetrics, because it changed the pytorch and torchvision installs to cpu types:
The following NEW packages will be INSTALLED:

future conda-forge/noarch::future-0.18.3-pyhd8ed1ab_0 None
libprotobuf conda-forge/linux-64::libprotobuf-3.20.2-h6239696_0 None
ninja conda-forge/linux-64::ninja-1.11.0-h924138e_0 None
pytorch pkgs/main/linux-64::pytorch-1.12.1-cpu_py310h9dbd814_1 None
torch-fidelity conda-forge/noarch::torch-fidelity-0.3.0-pyhd8ed1ab_0 None
torchmetrics conda-forge/noarch::torchmetrics-0.11.1-pyhd8ed1ab_0 None
torchvision conda-forge/linux-64::torchvision-0.14.1-cpu_py310hdfb2906_0 None

1 Like

This worked for me. Thanks @volkov-maxim

1 Like

This also happens to me on on MacBook Pro M1 Pro using conda:

conda env create -n torch-issue python=3.10
conda activate torch-issue
conda install pytorch torchvision -c pytorch

It looks like the TorchVision installed package is not form the PyTorch source:

pytorch      2.0.1 py3.10_0            pytorch
torchvision 0.13.1 cpu_py310he5d19f7_0

Installing with the explicit source for TorchVision solves the issue:

conda install pytorch pytorch::torchvision -c pytorch
1 Like

Thank you! This lead to a rabbit hole that eventually worked with installing pytorch2.0.0 and the associated torchivision version, as detailed in https://pytorch.org/get-started/pr]\evious-versions/.
The command I ran is conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 pytorch-cuda=11.8 -c pytorch -c nvidia

this worked for me thanks!