Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Error: DLL loaded failed when import torchvision #7468

Closed
Ieunn opened this issue Mar 27, 2023 · 7 comments
Closed

Import Error: DLL loaded failed when import torchvision #7468

Ieunn opened this issue Mar 27, 2023 · 7 comments

Comments

@Ieunn
Copy link

Ieunn commented Mar 27, 2023

馃悰 Describe the bug

The error happened when I'm doing this:

import torch
print(torch.version)
2.0.0+cu118
import torchvision
Traceback (most recent call last):
File "", line 1, in
File "C:\Coding\Anaconda\envs\stable-diffusion-webui\lib\site-packages\torchvision_init_.py", line 6, in
from torchvision import datasets, io, models, ops, transforms, utils
File "C:\Coding\Anaconda\envs\stable-diffusion-webui\lib\site-packages\torchvision\datasets_init_.py", line 1, in
from ._optical_flow import FlyingChairs, FlyingThings3D, HD1K, KittiFlow, Sintel
File "C:\Coding\Anaconda\envs\stable-diffusion-webui\lib\site-packages\torchvision\datasets_optical_flow.py", line 10, in
from PIL import Image
File "C:\Coding\Anaconda\envs\stable-diffusion-webui\lib\site-packages\PIL\Image.py", line 103, in
from . import _imaging as core
ImportError: DLL load failed while importing _imaging

The answers on Google said it's caused by unmatch of versions for pytorch and torchvision, but I've remove pytorch and torchvision several times and install them either by command line from official website or by pip locally install. But I still got this error whatever I do.

Versions

PyTorch version: 2.0.0+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A

Python version: 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:00:38) [MSC v.1934 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.22621-SP0
Is CUDA available: True
CUDA runtime version: 12.1.66
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4080 Laptop GPU
Nvidia driver version: 531.29
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.3
[pip3] open-clip-torch==2.16.0
[pip3] pytorch-lightning==1.9.4
[pip3] torch==2.0.0+cu118
[pip3] torchaudio==2.0.0
[pip3] torchdiffeq==0.2.3
[pip3] torchmetrics==0.11.4
[pip3] torchsde==0.2.5
[pip3] torchvision==0.15.1+cu118
...
[conda] numpy 1.23.3 pypi_0 pypi
[conda] open-clip-torch 2.16.0 pypi_0 pypi
[conda] pytorch-cuda 11.8 h24eeafa_3 pytorch
[conda] pytorch-lightning 1.9.4 pypi_0 pypi
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torch 2.0.0+cu118 pypi_0 pypi
[conda] torchaudio 2.0.0 pypi_0 pypi
[conda] torchdiffeq 0.2.3 pypi_0 pypi
[conda] torchmetrics 0.11.4 pypi_0 pypi
[conda] torchsde 0.2.5 pypi_0 pypi
[conda] torchvision 0.15.1+cu118 pypi_0 pypi

@pmeier
Copy link
Collaborator

pmeier commented Mar 27, 2023

File "C:\Coding\Anaconda\envs\stable-diffusion-webui\lib\site-packages\PIL\Image.py", line 103, in
from . import _imaging as core
ImportError: DLL load failed while importing _imaging

The error is coming from PIL (install name Pillow) not from torchvision. The reason you are seeing this when importing torchvision is because we are importing PIL.

@Ieunn
Copy link
Author

Ieunn commented Mar 27, 2023

File "C:\Coding\Anaconda\envs\stable-diffusion-webui\lib\site-packages\PIL\Image.py", line 103, in
from . import _imaging as core
ImportError: DLL load failed while importing _imaging

The error is coming from PIL (install name Pillow) not from torchvision. The reason you are seeing this when importing torchvision is because we are importing PIL.

Yes I notced that and tried to reinstall pillow once but it didn't work.

@pmeier
Copy link
Collaborator

pmeier commented Mar 27, 2023

What do you get when running python -c 'import PIL'?

@Ieunn
Copy link
Author

Ieunn commented Mar 27, 2023

What do you get when running python -c 'import PIL'?

seems nothing happened...I get into next command line without error prompt.

@pmeier
Copy link
Collaborator

pmeier commented Mar 27, 2023

What about python -c 'from PIL import Image'?

@Ieunn
Copy link
Author

Ieunn commented Mar 27, 2023

What about python -c 'from PIL import Image'?

Okay now I got a similar error prompt as what I got when import torchvision.

Traceback (most recent call last):
File "", line 1, in
File "C:\Coding\Anaconda\envs\deep_learning\lib\site-packages\PIL\Image.py", line 100, in
from . import _imaging as core
ImportError: DLL load failed while importing _imaging

So does it mean the problem is caused by pillow and I should try to find and reinstall some matched version of pillow?

@pmeier
Copy link
Collaborator

pmeier commented Mar 27, 2023

So does it mean the problem is caused by pillow

Yes.

I should try to find and reinstall some matched version of pillow?

Not sure what you mean here. This is not a version problem. PIL.Image is the core namespace of the package and thus wasn't added recently or the like. Basically everything PIL>=8 should be fine with torchvision. What version do you have?

I suspect PIL is not correctly installed and you need to fix that. How did you install in the first place?

In any case, this is out of scope for torchvision. Thus, I'm closing this.

@pmeier pmeier closed this as completed Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants