No module named '_bz2' in python3

Sifat Muhammad Abdullah picture Sifat Muhammad Abdullah · May 14, 2018 · Viewed 10.6k times · Source

When trying to execute the following command:

import matplotlib.pyplot as plt

The following error occurs:

from _bz2 import BZ2Compressor, BZ2Decompressor ImportError: No module named '_bz2'

So, I was trying to install bzip2 module in Ubuntu using :

sudo pip3 install bzip2

But, the following statement pops up in the terminal:

Could not find a version that satisfies the requirement bzip2 (from versions: ) No matching distribution found for bzip2

What can I do to solve the problem?

Answer

ospider picture ospider · Dec 10, 2018

If you compiling python yourself, you need to install libbz2 headers and .so files first, so that python will be compiled with bz2 support.

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