# やりたいこと

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)
    
    
```
CC BY-SA 4.0
2019-07-24T06:21:41.753
56859
2019-08-12T09:42:44.747
2019-08-12T09:42:44.747
19524
19524
question
python
lzmaライブラリをインポートできません。
liblzma-devを入れてから、Python仮想環境(3.7.4)をいったん消して作り直す。
CC BY-SA 4.0
2019-07-26T02:51:15.453
56900
2019-07-26T02:51:15.453
35262
56859
answer
以下のプロセスに従ってください

```

    $ sudo apt update && sudo apt upgrade
    $ export LC_ALL=C
    $ sudo pip install pipenv
    $ pipenv run python -c "import lzma"
       Traceback (most recent call last):
       File "<string>", line 1, in <module>
    
    $ pipenv run python3.7 -c "import lzma"
     Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/local/lib/python3.7/lzma.py", line 27, in <module>
        from _lzma import *
      ModuleNotFoundError: No module named '_lzma'
    
    $ sudo apt-get install python-lzma
    $ pip3.7 install pyliblzma
    
    # if not works, try
    $ sudo apt install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.5 libgdm-dev libdb4o-cil-dev libpcap-dev
    $ cd ~/<path>/Python3.7
    $ sudo ./configure
    $ sudo make
    $ sudo make install
    
    $ cat cat test.py
    import lzma
    data = b"Insert Data Here"
        with lzma.open("file.xz", "w") as f:
        f.write(data)
    $ pipenv run python3.7 test.py
    $ $ strings file.xz
    7zXZ
    Insert Data Here
    
```
CC BY-SA 4.0
2019-08-08T19:29:07.523
57260
2019-08-08T19:29:07.523
35404
56859
answer