Pandas: ModuleNotFoundError: No module named '_lzma'

Created on 23 Jul 2019  ยท  5Comments  ยท  Source: pandas-dev/pandas

Code Sample, a copy-pastable example if possible

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pandas

Problem description

Can't import last pandas release (0.25.0).

I've installed pandas using pipenv:

$ pipenv --three
$ pipenv shell
[pandas-lzma-error-bWkvwYXV]$ pipenv install pandas                                                                                                                                                                                         
Installing pandas...                                                                                                                                                                                                                        
Adding pandas to Pipfile's [packages]...
โœ” Installation Succeeded 
Pipfile.lock not found, creating...                                                                                                                                                                                                         
Locking [dev-packages] dependencies...                                                                                                                                                                                                      
Locking [packages] dependencies...                                                                                                                                                                                                          
โœ” Success! 
Updated Pipfile.lock (713200)!
Installing dependencies from Pipfile.lock (713200)...
  ๐Ÿ   โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰ 5/5 โ€” 00:00:01

Test import:

[pandas-lzma-error-bWkvwYXV]$ /usr/bin/env python
Python 3.7.1 (default, Nov 23 2018, 11:31:00) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/lib/python3.7/site-packages/pandas/__init__.py", line 55, in <module>
    from pandas.core.api import (
  File "/home/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/lib/python3.7/site-packages/pandas/core/api.py", line 24, in <module>
    from pandas.core.groupby import Grouper, NamedAgg
  File "/home/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/lib/python3.7/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
    from pandas.core.groupby.generic import (  # noqa: F401
  File "/home/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/lib/python3.7/site-packages/pandas/core/groupby/generic.py", line 44, in <module>
    from pandas.core.frame import DataFrame
  File "/home/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/lib/python3.7/site-packages/pandas/core/frame.py", line 88, in <module>
    from pandas.core.generic import NDFrame, _shared_docs
  File "/home/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/lib/python3.7/site-packages/pandas/core/generic.py", line 71, in <module>
    from pandas.io.formats.format import DataFrameFormatter, format_percentiles
  File "/home/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/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/user/.virtualenvs/pandas-lzma-error-bWkvwYXV/lib/python3.7/site-packages/pandas/io/common.py", line 9, in <module>
    import lzma
  File "/home/user/.pyenv/versions/3.7.1/lib/python3.7/lzma.py", line 27, in <module>
    from _lzma import *
ModuleNotFoundError: No module named '_lzma'
>>>

Downgrading to 0.24.2 fixes this issue.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-55-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: ru_RU.UTF-8
LOCALE: ru_RU.UTF-8

pandas: 0.25.0
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
None

Most helpful comment

Same issue on macOS. My steps were:

  • pip freeze > latestPackages.txt
  • pyenv uninstall 3.7.3
  • brew install xz (This is how you pick up the correct lzma macOS)
  • pyenv install 3.7.3

Quick test to make sure it worked:

  • pip install pandas Run python to import pandas and confirm it works.

Install all the packages you saved to latestPackages.txt

All 5 comments

Hmm did you have any issues when installing Python via pyenv? lzma is part of the standard library so surprised to see that in the backtrace

Hmm did you have any issues when installing Python via pyenv? lzma is part of the standard library so surprised to see that in the backtrace

Thanks, I've figure'd it out. I removed 3.7.1 with pyenv uninstall 3.7.1, installed dependencies sudo apt install liblzma-dev according pyenv wiki and reinstalled pyenv install 3.7.1. Pandas now importing without troubles. Sorry, for bother you with this issue.

Sorry, for bother you with this issue.

no problem. glad you got it sorted.

Same issue on macOS. My steps were:

  • pip freeze > latestPackages.txt
  • pyenv uninstall 3.7.3
  • brew install xz (This is how you pick up the correct lzma macOS)
  • pyenv install 3.7.3

Quick test to make sure it worked:

  • pip install pandas Run python to import pandas and confirm it works.

Install all the packages you saved to latestPackages.txt

@tvanyo Thanks for the suggestion.
I was having the same issue since I installed Python via pyenv, but reinstalling the same version after brew install xz solved the issue.

Can someone comment on whether the same problem happens on Windows if you have installed Python via pyenv?

Was this page helpful?
0 / 5 - 0 ratings