I've experience the same error in a RHEL 7.9 with a own python version (compiled from the scratch)
[lsaavedr@boxer ~]$ python3
Python 3.6.8 (default, Mar 7 2022, 12:20:27)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] 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.6/bz2.py", line 23, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
And I solved either copying or /symlink/ the bz2 shared library into the python3 directory tree:
[root@boxer python3.6]# pwd
/usr/local/lib/python3.6
[root@boxer python3.6]# ln -s ../../../lib64/python3.6/lib-dynload/_bz2.cpython-36m-x86_64-linux-gnu.so
[root@boxer python3.6]# rpm -qf ../../../lib64/python3.6/lib-dynload/_bz2.cpython-36m-x86_64-linux-gnu.so
python3-libs-3.6.8-19.el7_9.x86_64
Then bz2 works fine:
[lsaavedr@boxer ~]$ python3
Python 3.6.8 (default, Mar 7 2022, 12:20:27)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
>>> data = b"""All in all, it's just another brick in the wall"""
>>> c = bz2.compress(data)
>>> c
b'BZh91AY&SY\xc5\xd1nL\x00\x00\x05\x95\x80@\x84 \x00:}\x9e\x80 \x001L&\x9a\x03LA\xa8\x06\x86\x86\xd4i\xbe\x96d\xed\xb6\x96\x17x\x82EB\xd0\x02\x90\xe3\x0b\x88\xaa\x92\xec\x8a\xef/\x8b\xb9"\x9c(Hb\xe8\xb7&\x00'
>>> d = bz2.decompress(c)
>>> d
b"All in all, it's just another brick in the wall"
sudo pip3 -v install bzip2
for more verbose output. – Absolutiondpkg -l libpython3-stdlib
? – Loosestrife