tarfile compressionerror bz2模块不可用

时间:2016-07-28 20:45:11

标签: python linux django python-3.x bz2

我试图安装扭曲     pip install https://pypi.python.org/packages/18/85/eb7af503356e933061bf1220033c3a85bad0dbc5035dfd9a97f1e900dfcb/Twisted-16.2.0.tar.bz2#md5=8b35a88d5f1a4bfd762a008968fddabf

这适用于django-channels项目,我遇到以下错误问题

Exception:
Traceback (most recent call last):
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/tarfile.py", line 1655, in bz2open
    import bz2
  File "/usr/local/lib/python3.5/bz2.py", line 22, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named '_bz2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/petarp/.virtualenvs/CloneFromGitHub/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/commands/install.py", line 310, in run
    wb.build(autobuilding=True)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/wheel.py", line 750, in build
    self.requirement_set.prepare_files(self.finder)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/req/req_set.py", line 370, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/req/req_set.py", line 587, in _prepare_file
    session=self.session, hashes=hashes)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/download.py", line 810, in unpack_url
    hashes=hashes
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/download.py", line 653, in unpack_http_url
    unpack_file(from_path, location, content_type, link)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/utils/__init__.py", line 605, in unpack_file
    untar_file(filename, location)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/site-packages/pip/utils/__init__.py", line 538, in untar_file
    tar = tarfile.open(filename, mode)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/tarfile.py", line 1580, in open
    return func(name, filemode, fileobj, **kwargs)
  File "/home/petarp/.virtualenvs/ErasmusCloneFromGitHub/lib/python3.5/tarfile.py", line 1657, in bz2open
    raise CompressionError("bz2 module is not available")
tarfile.CompressionError: bz2 module is not available

显然我错过了bz2模块,因此我尝试手动安装它,但这对python 3.5没有用,所以我怎么解决此?

我已经完成了@ e4c5的建议,但我为python3.5.1做了,输出是

➜  ~ python3.5                               
Python 3.5.1 (default, Apr 19 2016, 22:45:11) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/bz2.py", line 22, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named '_bz2'
>>> 
[3]  + 18945 suspended  python3.5
➜  ~ dpkg -S /usr/local/lib/python3.5/bz2.py
dpkg-query: no path found matching pattern /usr/local/lib/python3.5/bz2.py

我使用的是Ubuntu 14.04 LTS,我已经从源代码安装了python 3.5。

3 个答案:

答案 0 :(得分:1)

我的python 3.4安装上的import bz2似乎没有任何问题。所以我做了

import bz2
print (bz2.__file__)

发现它位于/usr/lib/python3.4/bz2.py然后我做了

dpkg -S /usr/lib/python3.4/bz2.py

这表明:

  

libpython3.4-stdlib:amd64:/usr/lib/python3.4/bz2.py

因此,以下命令应该可以解决这个问题:

apt-get install libpython3.4-stdlib

<强>更新

如果你从源代码编译了python 3.5,很可能bz2还没有被编译进来。请先重新安装

./configure --with-libs='bzip' 

同样适用于python 3.6。请注意,这可能会抱怨其他缺少的依赖项。您将不得不逐个安装缺少的依赖项,直到所有内容都被覆盖。

答案 1 :(得分:0)

我能够通过删除Click Group [Arguments] ${group} Click Row ${group} 并将导入更改为

来解决它
Click Row
    [Aliases]    Click Group    Click Resource
    [Arguments]    ${target}
    Blah Blah

答案 2 :(得分:0)

在ubuntu上,apt-get install libbz2-dev然后再次编译python。