ModuleNotFoundError: No module named '_lzma'
Asked Answered
S

5

3

I am trying to plot in metpy with the help of "xarray with MetPy Tutorial". For that, I am getting error when am running following modules in:

'import cartopy.crs as crs'
'import cartopy.feature as cfeature'
'import matplotlib.pyplot as plt'
'import xarray as xr'
'import metpy.calc as mpcalc'
'from metpy.testing import get_test_data'
'from metpy.units import units.'

ModuleNotFoundError: No module named '_lzma'

like those errors will appear so anyone help me.

Thanks in Advance.

Seamanship answered 6/8, 2019 at 7:45 Comment(0)
B
1

I experienced this error with python 3.7.3 as well. Switching to Python 3.6.5 :: Anaconda, Inc. solved my problem.

Bullnecked answered 8/8, 2019 at 3:24 Comment(0)
E
1

My method may be helpful to you.

I was running Docker Desktop and Ubuntu 20.04 Container on Windows x64 at the time.

I installing liblzma-dev using apt-get firstly, then rebuilt Python 3.10.9, and it worked properly. The steps are as follows:

# installing liblzma-dev
apt-get install -y liblzma-dev

# prepare Python3.10.9 source and unzip
wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz && \
tar -xf Python-3.10.9.tgz && \
cd /Python-3.10.9

# configure and compile Python
./configure --enable-optimizations && make -j$(nproc)

# installing Python
make altinstall

In general, first install liblzma-dev or other libs in advance, then compile and install Python, and these modules can be used

Ethmoid answered 7/12, 2023 at 16:22 Comment(0)
S
0

This appears to be an issue with your Python build, rather than with MetPy, as _lzma is part of the standard library. From a quick Google search, it seems like this may be an issue with Ubuntu? At any rate, if you google the error, you'll find quite a few solutions to this issue, depending on what your operating system is. We suggest using the Anaconda distribution of Python (https://www.anaconda.com/distribution/), which is easy to set up, and haven't had anyone report this issue before using that stack.

Sylvanus answered 6/8, 2019 at 13:54 Comment(0)
W
0

I just ran into the same error and blogged about it here. Basically the underscore in the module name hints that it is a module written in C or C++. The reason it is missing from your system is most likely because of a missing system dependencies during installation of the python interpreter. If you installed Python with pyenv they have documented which dependencies should be installed by plattform. Conda does not have that particular problem as it ships with binary dependencies.

Whiting answered 26/6, 2021 at 18:6 Comment(0)
B
0

I had installed backports.lzma via pip after installing debian packages such as liblzma-dev and assorted build tools, but it would continue to fail to find the module.

I fixed it by adding a fallback import:

try:
    import lzma
except ImportError:
    import backports.lzma as lzma

Using python 3.7.

Barbour answered 1/3, 2023 at 0:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.