1

I'm trying to install twisted pip install https://pypi.python.org/packages/18/85/eb7af503356e933061bf1220033c3a85bad0dbc5035dfd9a97f1e900dfcb/Twisted-16.2.0.tar.bz2#md5=8b35a88d5f1a4bfd762a008968fddabf

This is for a django-channels project and I'm having the following error problem

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

Clearly I'm missing bz2 module, so I've tried to installed it manually, but that didn't worked out for python 3.5, so how can I solved this?

I've did what @e4c5 suggested but I did it for python3.5.1, the output is

➜  ~ 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

I am on Ubuntu 14.04 LTS and I have installed python 3.5 from source.

e4c5
  • 52,766
  • 11
  • 101
  • 134
copser
  • 2,523
  • 5
  • 38
  • 73
  • how did you try to install it manually and what is meant by it didn't work out? – e4c5 Jul 28 '16 at 22:53
  • maybe I didn't expressed it well, by manually I mean that I've installed it with `sudo apt-get install libbz2-dev`, but that didn't installed it for `python3.5`, I've still missing this module when I import it inside the python shell – copser Jul 29 '16 at 03:23

3 Answers3

4

I don't seem to have any problem with import bz2 on my python 3.4 installation. So I did

import bz2
print (bz2.__file__)

And found that it's located at /usr/lib/python3.4/bz2.py then I did

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

This reveals:

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

Thus the following command should hopefully fix this:

apt-get install libpython3.4-stdlib

Update:

If you have compiled python 3.5 from sources, it's very likely the bz2 hasn't been compiled in. Please reinstall by first doing

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

The same applies for python 3.6 as well. Note that this will probably complain about other missing dependencies. You will have to install the missing dependencies one by one until everything is covered.

e4c5
  • 52,766
  • 11
  • 101
  • 134
  • I've edited my question, I still have a problem with `python 3.5`, and yes this works for 3.4 version, and I have `bz2` on it – copser Jul 29 '16 at 03:41
  • what is your version of Ubuntu (or corresponding Ubuntu version for your distro) – e4c5 Jul 29 '16 at 03:57
  • I'm using Ubuntu 14.04 tls – copser Jul 29 '16 at 03:58
  • but that comes wth python 3.4 if am not mistaken. What was the process for your python 3.5 installation? – e4c5 Jul 29 '16 at 04:06
  • I'm not understanding you well, I've installed python3.5 from the source, but should this module be in python3.5, it's in python3.4, and the docs covers it https://docs.python.org/3/library/bz2.html – copser Jul 29 '16 at 04:20
  • Got the error `Fatal: You must get working getaddrinfo() function or you can specify "--disable-ipv6"`. Had to do just that to compile. Note that the error would only occur with the bzip flag – Jacob Sánchez Aug 04 '20 at 05:13
0

I was able to solve it by removing the _ and changing the import to

from bz2 import BZ2Compressor, BZ2Decompressor
Michael Lihs
  • 7,460
  • 17
  • 52
  • 85
0

On ubuntu, apt-get install libbz2-dev then compile python again.

hassanzadeh.sd
  • 3,091
  • 1
  • 17
  • 26