Unable to import lzma library.

Asked 2 years ago, Updated 2 years ago, 29 views

I'd like to use the pandas 0.25.0.
However, when I tried to import pandas, I got an error that lzma could not be imported.

$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/python 3.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/python 3.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/python 3.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/python 3.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/python 3.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/python 3.7/site-packages/pandas/core/generic.py", line 71, in<module>
    from pandas.io.forms.format import DataFrameFormatter, format_percentiles
  File "/home/vagrant/.local/share/virtualenvs/annofab-cli-fQbMtggr/lib/python 3.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/python 3.7/site-packages/pandas/io/common.py", line 9, in<module>
    import lzma
  File"/home/vagrant/.pyenv/versions/3.7.4/lib/python 3.7/lzma.py", line 27, in <module>
    from_lzma import*
ModuleNotFoundError: No module named '_lzma'

Why can't the standard library lzma import?
Also, how can I solve this problem?

$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/python 3.7/lzma.py", line 27, in <module>
    from_lzma import*
ModuleNotFoundError: No module named '_lzma'

After installing liblzma-dev, I installed Python 3.7.4 with PyEnv, but I could not import it.

$sudo apt install liblzma-dev
Loading package list... Done
Creating dependency tree                
Reading state information...completed
liblzma-dev is already the latest version (5.2.2-1.3).
Upgrade: 0, New Install: 0, Delete: 0, Hold: 116.
  • python 3.7.4
  • pyenv1.2.8
  • pandas 0.25.0
  • pipenv2018.11.26
  • ubuntu 18.04
  • liblzma-dev5.2.2-1.3
$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' '' ''))'eg_info --eg-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 error out with exit status 1: python setup.py eg_info Check the logs for full command output.

pip version

$which pip
/home/vagrant/.pyenv/shims/pip
$ pip -- version
pip 19.2.1 from/home/vagrant/.pyenv/versions/3.7.4/lib/python 3.7/site-packages/pipe (python 3.7)
$ type pip
pip is hashed (/home/vagrant/.pyenv/shims/pip)

python

2022-09-30 21:42

2 Answers

Add liblzma-dev and then erase and recreate the Python virtual environment (3.7.4).


2022-09-30 21:42

Follow the process below

$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 python 3.7-c "import lzma"
 Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python 3.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 libtk 8.5 libgdm-dev libdb4o-cil-dev libpcap-dev
$ cd through /<path>/Python 3.7
$ sudo./configure
$ sudo make
$ sudo make install

$ cat test.py
import lzma
data=b "Insert Data Here"
    with lzma.open("file.xz", "w") asf:
    f.write(data)
$ pipenv run python 3.7 test.py
$ $string file.xz
7zXZ
Insert Data Here


2022-09-30 21:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.