ubuntu下_import pandas出现Could not import the lzma module

运行环境:

pyenv python =3.6.8

pandas = 1.1.5

OS = Ubuntu 18.04

 问题描述:

        pandas库可以安装成功,但是在import的时候出现了错误提示

        UserWarning: Could not import the lzma module......        

Python 3.6.8 (default, Nov  9 2021, 00:29:48) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
/home/kql/.pyenv/versions/kql/lib/python3.6/site-packages/pandas/compat/__init__.py:120: UserWarning:
 Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma 
compression will result in a RuntimeError.
  warnings.warn(msg)
>>> 

解决: 

安装libbz2-dev, lzma,liblzma-dev  然后pip install backports.lzma

sudo apt-get install libbz2-dev

sudo apt-get install lzma

sudo apt-get install liblzma-dev

pip install backports.lzma

接着找到lzma.py文件,修改文件27,28两行

        from _lzma import *
        from _lzma import _encode_filter_properties, _decode_filter_properties

#找到lzma.py文件的位置
find / -name lzma.py
/home/kql/.pyenv/versions/3.6.8/lib/python3.6/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

再次导入无报错。

引用:

Python 安装pandas库出现Could not import the lzma moduleicon-default.png?t=LA92https://www.cnblogs.com/gaodp/p/15270116.html

你可能感兴趣的:(ubuntu,c语言,python)