Tag Archives: Could not import the lzma module

[Solved] Python import pandastime Error: Could not import the lzma module

# Install xz-devel in centos and recompile it

yum install xz-devel

./configure --enable-optimizations

#install backports.lzma package

pip install backports.lzma

Modify python file

# /usr/local/python3.x/lib/lzma.py

Original:

from _lzma import * 
    
from _lzma import _encode_filter_properties, _decode_filter_properties 

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 

Python installs pandas library Error: Could not import the LZMA module appears when

environment

pyenv python =3.7.0
pandas = 1.3.2
OS = Ubuntu 16.04

report errors

There is a warning prompt after installing the pandas reference

Solution:

sudo apt-get install libbz2-dev
sudo apt-get install  lzma
sudo apt-get install  liblzma-dev	


pip install backports.lzma

Find the file lzma.py and modify line 27

find/-name lzma.py
/root/.pyenv/versions/3.7.3/lib/python3.7/lzma.py

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

Import pandas again.

No problem!