0

In python3.6, when executing the following command:

from sklearn.model_selection import GridSearchCV

Reported Error:

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

However, issue is that I don't have root access to machine to use the solutions posted on the same issue on stackoverflow.

On trying to locate libbz2.so, I received following:

/usr/lib64/libbz2.so.1
/usr/lib64/libbz2.so.1.0.6

To be noted: in my bash_profile the LIBRARY_PATH did not have '/usr/lib64' explicitly specified when I compiled python3.6 from source.

Su JK
  • 161
  • 1
  • 5
  • 13
  • Side-note: using virtual-environments you should be able to install those non-system libraries without any problem (assuming venv is available). – sascha Jul 19 '17 at 21:38

1 Answers1

3

bz2 is an optional dependency of python, but sklearn assumes your python installation has this module.

There are at least two possible ways to fix this:

  1. update your version of joblib to make its dependence on bz2 optional. (Thanks to sascha for pointing this out.)
  2. or, install libbz2 and then re-build python3.6.
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • From that issue in this link, it sounds like installing a new version of joblib (> 10/2016) might be enough. – sascha Jul 19 '17 at 21:39
  • @unutbu: I added some more info. Can you comment on it? – Su JK Jul 19 '17 at 21:55
  • @SuJK I highly recommend going for approach 1 (update joblib) first. Foreseeing all the consequences of building python yourself (if it's one global install, you might destroy system-dependencies) seems hard. Also your non-root access should stand in the way. – sascha Jul 19 '17 at 21:57
  • @SuJK: If you do want bz2 enabled in python, I believe this is [the way to do it](https://stackoverflow.com/a/10972897/190597) (for linux). Be sure to read the comment about `make clean` too. – unutbu Jul 19 '17 at 22:10
  • @SuJK: You may also need to pass `./configure` an option to specify where to find libbz2. Run `./configure --help` to find the right option. – unutbu Jul 19 '17 at 22:17
  • As a quick fix, I just tracked down all the files which imported `bz2` and removed the lines. It seems to work right now. But I will recompile my Python. – Su JK Jul 19 '17 at 22:28