Skip to content

Instantly share code, notes, and snippets.

@iandanforth
Created July 19, 2019 02:28
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandanforth/f3ac42b0963bcbfdf56bb446e9f40a33 to your computer and use it in GitHub Desktop.
Save iandanforth/f3ac42b0963bcbfdf56bb446e9f40a33 to your computer and use it in GitHub Desktop.
ModuleNotFoundError: No module named '_lzma'

If you see this error when trying to import pandas under osx 10.14 Mojave

ModuleNotFoundError: No module named '_lzma'

You may be missing the xz libraries (https://tukaani.org/xz/)

This may be corrected by using homebrew to install it.

brew install xz

You then need to rebuild the Python you are using with pandas.

If you happen to be using pyenv then you can run

pyenv uninstall 3.6.4  # Replace with your version number
pyenv install 3.6.4  # Reinstall (now with the lzma lib available)
pyenv local 3.6.4  # Set this version to always run in this directory
pip install pandas

You should now be able to import pandas!

@Cqxstevexw
Copy link

it works, thanks!

@coryroyce
Copy link

I had this same issue and had tried several different ways to fix it and this one worked. I really appreciate you sharing it here.

@naveenwashere
Copy link

Worked for me too. Thanks!

@codeslp
Copy link

codeslp commented Feb 7, 2023

THANK YOU FOR POSTING THIS IT WAS SO HELPFUL. I was trying to make a webscraper with scrapy and it wanted to use this.

@leaveslm
Copy link

leaveslm commented Mar 6, 2023

It worked on my Mac.
macOS Monterey 12.6.3, M1 Pro

@fox-chad
Copy link

fox-chad commented Mar 9, 2023

Worked on Big Sur, too

@Cbrower17
Copy link

Worked for me! (big sur)

@mansimransingh
Copy link

The mentioned solution didn't work for me (macos Ventura / intel).

However, this did:

CPPFLAGS="-I$(brew --prefix xz)/include" pyenv install 3.10.0

Found on: https://stackoverflow.com/a/70265883/2303348

@danny460
Copy link

danny460 commented May 8, 2023

Works Monterey, TY!

@islam3zzat
Copy link

Worked for me!
Thanks for sharing ❤️

@subratamal
Copy link

Worked. Saved a ton of time, thanks.

@zhanerkeussen
Copy link

Thank you!

@bonatoc
Copy link

bonatoc commented Jan 5, 2024

Brew clearly states it:

$ brew install _lzma

Warning: No available formula with the name "_lzma".
lzma is now part of the xz formula

...but many thanks, good catch, 'xz' reads like an error, I had to google it.

@gurugv
Copy link

gurugv commented Jan 19, 2024

CFLAGS="-I$(brew --prefix xz)/include" LDFLAGS="-L$(brew --prefix xz)/lib" pyenv install 3.11.7

this worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment