ModuleNotFoundError: No module named '_bz2'

  File "/usr/local/lib/python3.7/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/local/lib/python3.7/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/local/lib/python3.7/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/opt/deployment/venv/lib/python3.7/site-packages/prodigy/__init__.py", line 9, in <module>
    from . import recipes  # noqa
  File "/opt/deployment/venv/lib/python3.7/site-packages/prodigy/recipes/__init__.py", 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/dep.py", 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/bz2.py", 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.

2 Likes

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/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/alba/plx_python/util/prodigy/multisessions.py", line 46, in serve
    prodigy.serve(
  File "/opt/alba/venv/lib/python3.8/site-packages/prodigy/__init__.py", 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/db.py", line 72, in connect
    _DB = Database(db, db_id, db_name)
  File "/opt/alba/venv/lib/python3.8/site-packages/prodigy/components/db.py", line 180, in __init__
    DB_PROXY.initialize(db)
  File "/opt/alba/venv/lib/python3.8/site-packages/peewee.py", line 421, in initialize
    callback(obj)
  File "/opt/alba/venv/lib/python3.8/site-packages/peewee.py", line 4641, in _db_hook
    self._constructor = database.get_binary_type()
  File "/opt/alba/venv/lib/python3.8/site-packages/peewee.py", 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: