前提
pyenv で python 3.X をインストールしていること
エラー内容
Traceback (most recent call last):
File "test.py", line 6, in <module>
from sklearn.feature_extraction.text import TfidfVectorizer
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sklearn/base.py", line 12, in <module>
from .utils.fixes import signature
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sklearn/utils/__init__.py", line 18, in <module>
from ..externals.joblib import cpu_count
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sklearn/externals/joblib/__init__.py", line 122, in <module>
from .memory import Memory, MemorizedResult
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sklearn/externals/joblib/memory.py", line 37, in <module>
from . import numpy_pickle
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sklearn/externals/joblib/numpy_pickle.py", line 16, in <module>
from .numpy_pickle_utils import _COMPRESSORS
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sklearn/externals/joblib/numpy_pickle_utils.py", line 12, in <module>
import bz2
File "/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/bz2.py", line 20, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named '_bz2'
解決策
ググると
$ sudo yum install bzip2-devel
で解決とあるんだけど、これをした上で、python そのものをインストールしなおす必要がある。
$ pyenv install 3.4.3
$ pyenv global 3.4.3
で動くようになる。