やりたいこと

pandas 0.25.0を使いたいです。
しかし、pandasをimportしようとすると、lzmaがインポートできない、というエラーが発生しました。

$ pipenv run python -c "import pandas; print(pandas.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/__init__.py", line 55, in <module>
    from pandas.core.api import (
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/core/api.py", line 24, in <module>
    from pandas.core.groupby import Grouper, NamedAgg
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
    from pandas.core.groupby.generic import (  # noqa: F401
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/core/groupby/generic.py", line 44, in <module>
    from pandas.core.frame import DataFrame
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/core/frame.py", line 88, in <module>
    from pandas.core.generic import NDFrame, _shared_docs
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/core/generic.py", line 71, in <module>
    from pandas.io.formats.format import DataFrameFormatter, format_percentiles
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/io/formats/format.py", line 47, in <module>
    from pandas.io.common import _expand_user, _stringify_path
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python3.7/site-packages/pandas/io/common.py", line 9, in <module>
    import lzma
  File "/home/vagrant/.pyenv/versions/3.7.4/lib/python3.7/lzma.py", line 27, in <module>
    from _lzma import *
ModuleNotFoundError: No module named '_lzma'

質問

標準ライブラリ lzmaがimportできないのはなぜでしょうか?
また、どうすれば解決できますか?

$ pipenv run python -c "import lzma"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/vagrant/.pyenv/versions/3.7.4/lib/python3.7/lzma.py", line 27, in <module>
    from _lzma import *
ModuleNotFoundError: No module named '_lzma'

liblzma-devをインストールしてから、PyEnvでPython3.7.4をインストールしましたが、importはできませんでした。

$sudo apt install liblzma-dev
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
liblzma-dev はすでに最新バージョン (5.2.2-1.3) です。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 116 個。

環境

  • python 3.7.4
  • pyenv 1.2.8
  • pandas 0.25.0
  • pipenv 2018.11.26
  • ubuntu 18.04
  • liblzma-dev 5.2.2-1.3

補足

pyliblzmaのインストール

$ pip install pyliblzma
Collecting pyliblzma
  Downloading https://files.pythonhosted.org/packages/17/48/5292ade507dafe573360560ba53783395587dc42eb32b347feb2ac70fc6b/pyliblzma-0.5.3.tar.bz2 (43kB)
     |████████████████████████████████| 51kB 3.2MB/s 
    ERROR: Command errored out with exit status 1:
     command: /home/vagrant/.pyenv/versions/3.7.4/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jv1rz7us/pyliblzma/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jv1rz7us/pyliblzma/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-install-jv1rz7us/pyliblzma/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-jv1rz7us/pyliblzma/setup.py", line 40, in <module>
        for i in xrange(len(c_files)):
    NameError: name 'xrange' is not defined
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

pipのバージョン

$ which pip
/home/vagrant/.pyenv/shims/pip
$ pip --version
pip 19.2.1 from /home/vagrant/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pip (python 3.7)
$ type pip
pip はハッシュされています (/home/vagrant/.pyenv/shims/pip)