I’m using python 3.7.10 with torch 1.81 and torchvision 0.9.1 in my machine and while importing dset from torchvision.dataset this error shows up:
Traceback (most recent call last):
File "train.py", line 23, in <module>
from dataloader import load_data
File "/home/rdb/Prithviraj/Image-Restoration-in-Occluded-Images-using-GANs/dataloader.py", line 3, in <module>
import torchvision.datasets as dset
File "/home/rdb/.local/lib/python3.7/site-packages/torchvision/__init__.py", line 7, in <module>
from torchvision import datasets
File "/home/rdb/.local/lib/python3.7/site-packages/torchvision/datasets/__init__.py", line 6, in <module>
from .mnist import MNIST, EMNIST, FashionMNIST, KMNIST, QMNIST
File "/home/rdb/.local/lib/python3.7/site-packages/torchvision/datasets/mnist.py", line 11, in <module>
import lzma
File "/usr/local/lib/python3.7/lzma.py", line 27, in <module>
from _lzma import *
ModuleNotFoundError: No module named '_lzma'
This means that the torchvision I have is broken or buggy. Can someone suggest a fix for this error.
If u need a demo code to run then please use this tutorial .
This could work. However, note that lzma should be a default Python package starting from Python 3.5, so unsure why it’s missing in your environment.
A related issue is here with more suggestions.
Ya, i have read this thread and it says that the fix is to do lazy import or something. But I don’t really understand it as _lmza should be imported by default when torchvision is imported. and as you said it is a default python package but the difference is I’m using python version 3.7.10 and you have mentioned about python3.5
Any suggestions what I should do next?
You could follow this advice, install the missing library, and then reinstall Python so that it’ll add the support. Alternatively, you could also search for other standalone Python libs (such as in your previous suggestion), but I haven’t tried to install any of them.
I tried to install that package but it says that the package is already up to date
sudo apt-get install -y liblzma-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
liblzma-dev is already the newest version (5.1.1alpha+20120614-2ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
I don’t think it’s an issue in torchvision, as lzma should be a default Python package, and thus it would be a valid dependency.
I don’t know why your Python setup isn’t recognizing it, so you might need to create a new environment maybe.
and as you can see there is no package called _lmza
So know that we have established that I don’t have this package, how should I add it ?
By now, I have tried using the following commands:
Something still seems to be strange in your Python setup.
Which Python version are you using and are you seeing the lzma.py file in the pythonMAJOR.MINOR dir?
I had the same issue using debian, and solved it by removing lzma import in {venv_dir}/.../torchvision/datasets/utils.py
On line ~240 of utils.py I replaced lzma with: