我该如何解决“没有名为‘_lzma’的模块”?

我该如何解决“没有名为‘_lzma’的模块”?

我正在尝试运行安装在 Ubuntu 20.04.1 LTS 中的 BoltzTraP2 软件,但出现此错误。请告诉我如何解决这个问题。我已经安装了 pandas 和 liblzma-dev,但仍然出现错误。

==========================================================
 you can install pyfftw to get better FFT performance
Traceback (most recent call last):
  File "/home/syl2/.local/bin/btp2", line 11, in <module>
    load_entry_point('BoltzTraP2==20.7.1', 'console_scripts', 'btp2')()
  File "/home/syl2/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 473, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/syl2/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/home/syl2/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2447, in load
    return self.resolve()
  File "/home/syl2/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2453, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python3.8/site-packages/BoltzTraP2/interface.py", line 58, in <module>
    import BoltzTraP2.serialization
  File "/usr/local/lib/python3.8/site-packages/BoltzTraP2/serialization.py", line 32, in <module>
    import lzma
  File "/usr/local/lib/python3.8/lzma.py", line 27, in <module>
    from _lzma import *
ModuleNotFoundError: No module named '_lzma'

答案1

非常抱歉,之前的回答是错误的。

忘记关于 pylzma 的一切。如果你修改了某些内容,请撤消它,我很抱歉让你走上这条路。我根据这篇文章得到了正确的答案:

https://github.com/ultralytics/yolov5/issues/1298

简而言之,pip install lzma 将不起作用,请改为执行以下操作:

pip install backports.lzma

然后进入你的 python 目录:

cd /usr/local/lib/python3.8

您将修改lzma.py文件。我只能以更高的权限级别执行此操作,所以我这样做了

sudo nano lzma.py

一开始有两行

from _lzma import *
from _lzma import _encode_filter_properties, _decode_filter_properties

将其修改为

from backports.lzma import *
from backports.lzma import _encode_filter_properties, _decode_filter_properties

保存并关闭文件。Boltztrap2 现在可以工作了。

相关内容