首先导入pandas会报出

/usr/local/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)

同时在使用pandas会报出

ModuleNotFoundError: No module named '_lzma'

网上的办法通过pip3来安装backports.lzma

python3 -m pip install backports.lzma

但是执行命令后报出 lzma.h文件缺失:

#############################################

  ERROR: Command errored out with exit status 1:

     command: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-n9y4spd6/backports-lzma_3a42847536ba4e8fa04706acf1c9735d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-n9y4spd6/backports-lzma_3a42847536ba4e8fa04706acf1c9735d/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ai67le6l/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/backports.lzma

         cwd: /tmp/pip-install-n9y4spd6/backports-lzma_3a42847536ba4e8fa04706acf1c9735d/

    Complete output (19 lines):

    This is backports.lzma version 0.0.14

    running install

    running build

    running build_py

    creating build

    creating build/lib.linux-x86_64-3.6

    creating build/lib.linux-x86_64-3.6/backports

    copying backports/__init__.py -> build/lib.linux-x86_64-3.6/backports

    creating build/lib.linux-x86_64-3.6/backports/lzma

    copying backports/lzma/__init__.py -> build/lib.linux-x86_64-3.6/backports/lzma

    running build_ext

    building 'backports.lzma._lzma' extension

    creating build/temp.linux-x86_64-3.6

    creating build/temp.linux-x86_64-3.6/backports

    creating build/temp.linux-x86_64-3.6/backports/lzma

    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/root/include -I/opt/local/include -I/usr/local/include -I/usr/local/include/python3.6m -c backports/lzma/_lzmamodule.c -o build/temp.linux-x86_64-3.6/backports/lzma/_lzmamodule.o

    backports/lzma/_lzmamodule.c:115:18: fatal error: lzma.h: No such file or directory

    compilation terminated.

    error: command 'gcc' failed with exit status 1

    ----------------------------------------

ERROR: Command errored out with exit status 1: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-n9y4spd6/backports-lzma_3a42847536ba4e8fa04706acf1c9735d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-n9y4spd6/backports-lzma_3a42847536ba4e8fa04706acf1c9735d/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ai67le6l/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/backports.lzma Check the logs for full command output.

#############################################

这里在ubuntu16.04下需要安装

apt-get install -y liblzma-dev

之后才能正常通过pip3 安装backports.lzma

更多推荐