No module named '_lzma' |

I'm working on Ubuntu 22.04 LTS and I'm trying to debug my python code within a virtual environment created with the help of pyenv and poetry 1.1.13 as a package manager.

I get this message in the debugging console trying to import

ModuleNotFoundError: No module named '_lzma'

when i try to import _lzma using:

from _lzma import * 

From what I can gather its related to package installation errors, I have tried installing it manually but the problem persists.

2 Answers

Based on pyenv wiki, you should install the desired python version with --enable-framework flag.

PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.7 

The reason is that the module you're trying to use is implemented in C, and CPython with shared libraries will be built with the aforementioned flag.

Solution

frist

yum install xz-devel yum install python-backports-lzma pip install backports.lzma 

second go to file where exeception originated

cd /usr/local/lib/python3.8 vi lzma.py 

finally modify about line 27 to

 try: from _lzma import * from _lzma import _encode_filter_properties, _decode_filter_properties except ImportError: from backports.lzma import * from backports.lzma import _encode_filter_properties, _decode_filter_properties 

it‘s work!I had to search for hours to get this problem to be solved.

Credit: Yolo5 issues

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobmtuaW2AcX6Op6ZmpZ%2BZwq2xjKeYpp2UYrm7ucA%3D

ncG1vNJzZmilp52%2Bb7%2FFqGpnnJmctrWty6ianpmeqL2ir8SsZZynnWS7sHnMqJuupJViu6K5xJ1kpbKdlnupwMyl