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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest