module not found error: no module named ‘_lzma’ when import torchvision using pyenv in M1 Mac

module not found error: no module named ‘_lzma’ when import torchvision using pyenv in M1 Mac

It is because you didn’t have XZ Utils in your mac when you compiled your python.

In my case, uninstall my current python version and install xz using homebrew and reinstall the python version that I removed.

pyenv uninstall 3.8.10
brew install xz
pyenv install 3.8.10
pyenv virtualenv 3.8.10 pytorch-3.8.10
pyenv activate pytorch-3.8.10
python
import torchvision

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: