ModuleNotFoundError: No module named '_bz2'

  File "/usr/local/lib/python3.7/", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/local/lib/python3.7/", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/local/lib/python3.7/", line 109, in _get_module_details
  File "/opt/deployment/venv/lib/python3.7/site-packages/prodigy/", line 9, in <module>
    from . import recipes  # noqa
  File "/opt/deployment/venv/lib/python3.7/site-packages/prodigy/recipes/", line 4, in <module>
    from . import dep, ner, textcat, pos, compare, terms, generic, image  # noqa
  File "/opt/deployment/venv/lib/python3.7/site-packages/prodigy/recipes/", line 12, in <module>
    from ..components.loaders import get_stream
  File "cython_src/prodigy/components/loaders.pyx", line 4, in init prodigy.components.loaders
  File "/usr/local/lib/python3.7/", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
    ModuleNotFoundError: No module named '_bz2'

I am getting the above when I am trying to use any of the prodigy commands. Checked stackoverflow none of them are working. Please can you help us out.
prodigy stats -l
prodigy dataset temp 'temp db'

Hmm, it looks like the error message you copy-pasted might be cut off? Is there a last line that shows what exactly fails?

It looks like your OS is probably missing the BZ2 decompression library. I think I provided the following list of Ubuntu packages in the other thread. I’m not sure what the CentOS equivalents are, but you should double-check you have the equivalents installed on your servers, to make sure everything works smoothly:

  • unzip
  • libssl-dev
  • zlib1g-dev
  • libbz2-dev
  • libreadline-dev
  • libsqlite3-dev
  • wget
  • curl
  • llvm
  • libncurses5-dev
  • libncursesw5-dev
  • xz-utils
  • python-pip
  • python-virtualenv
  • python3-pip
  • python3-venv
  • python-dev
  • python3-dev
  • libopenblas-base
  • libopenblas-dev

updated the last line

I have the same issue on debian python 3.8.1. I could apt install all the packages mentioned by @honnibal. @vajja did you manage to solve it or did you change OS?

@nix411 Did you reinstall/recompile Python afterwards? The issue seems to be pretty common (see here) and the solution typically involves installing BZ2 and then reconfiguring and recompiling Python.


Just ran into this issue again (last I just used another OS I think). This time I

sudo apt-get install libbz2-dev

and then recompiled Python 3.8.1 . It fixed the initial issue BUT now I get

Process Process-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/multiprocessing/", line 315, in _bootstrap
  File "/usr/local/lib/python3.8/multiprocessing/", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/alba/plx_python/util/prodigy/", line 46, in serve
  File "/opt/alba/venv/lib/python3.8/site-packages/prodigy/", line 36, in serve
    controller = loaded_recipe(*cli_args, use_plac=True)
  File "cython_src/prodigy/core.pyx", line 231, in prodigy.core.recipe.recipe_decorator.recipe_proxy
  File "cython_src/prodigy/core.pyx", line 71, in prodigy.core.Controller.__init__
  File "cython_src/prodigy/core.pyx", line 187, in prodigy.core.Controller.connect_db
  File "/opt/alba/venv/lib/python3.8/site-packages/prodigy/components/", line 72, in connect
    _DB = Database(db, db_id, db_name)
  File "/opt/alba/venv/lib/python3.8/site-packages/prodigy/components/", line 180, in __init__
  File "/opt/alba/venv/lib/python3.8/site-packages/", line 421, in initialize
  File "/opt/alba/venv/lib/python3.8/site-packages/", line 4641, in _db_hook
    self._constructor = database.get_binary_type()
  File "/opt/alba/venv/lib/python3.8/site-packages/", line 3607, in get_binary_type
    return sqlite3.Binary
AttributeError: 'NoneType' object has no attribute 'Binary'

Any suggestions?

I just realized that I need to compile python 3.8 with sqlite3. I am not the greatest compiler - anyone who can help me out?

I sudo apt-get install sqlite3 and recompiled again. Now it is working

1 Like

yes it's correct :ok_hand: