Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named '_lzma' #27532

Closed
islander opened this issue Jul 23, 2019 · 9 comments
Closed

ModuleNotFoundError: No module named '_lzma' #27532

islander opened this issue Jul 23, 2019 · 9 comments

Comments

@islander
Copy link

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

@WillAyd
Copy link
Member

WillAyd commented Jul 23, 2019

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

@islander
Copy link
Author

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.

@simonjayhawkins
Copy link
Member

Sorry, for bother you with this issue.

no problem. glad you got it sorted.

@tvanyo
Copy link

tvanyo commented Aug 1, 2019

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

@guilherme-salome
Copy link
Contributor

@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?

@oren0e
Copy link

oren0e commented Jan 16, 2021

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.

Actually for Ubuntu 18.04 installing liblzma-dev is not enough. You should also install lzma, e.g.:
sudo apt-get install lzma

@jmarrec
Copy link
Contributor

jmarrec commented Mar 26, 2021

For the record, I have hit pretty much all issues mentioned above on a mac mini M1.

Even with xz installed it wasn't picking it up. I solved it via:

brew install xz # To pick up liblzma
prefix=$(brew --prefix)
export LDFLAGS="-L$prefix/opt/xz/lib $LDFLAGS"
export CPPFLAGS="-I$prefix/opt/xz/include $CPPFLAGS"
export PKG_CONFIG_PATH="$prefix/opt/xz/lib/pkgconfig:$PKG_CONFIG_PATH"
# YOU CANNOT HAVE THE GNUBINS in your PATH when you run this
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.9.2
python3 -c "import lzma" # should work and not throw "cannot import _lzma"

@robertoweller
Copy link

That's what solved it for me

sudo apt-get install libbz2-dev
sudo cp /usr/lib/python3.8/lib-dynload/_bz2.cpython-38-x86_64-linux-gnu.so/usr/local/lib/python3.8/
sudo cp /usr/lib/python3.8/lib-dynload/_lzma.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.8/

@realsanjeev
Copy link

Solution

frist

yum install xz-devel
yum install python-backports-lzma
pip install backports.lzma

second

cd /usr/local/lib/python3.8
vi lzma.py 

finally
modify about line 27


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

it‘s work!I had to search for hours to get this problem to be solved.

Credit: Yolo5 issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants