pythonscikit-learnscikits

Cannot import scikits-learn even though it seems to be installed


Per the scikit-learn user guide, I installed scikit-learn using pip install -U scikit-learn.

So using pip search scikit-learn, I get this search result:

scikit-learn - A set of python modules for machine learning and data mining
INSTALLED: 0.12.1 (latest)

But when I go into Python and try to import sklearn, I get an ImportError: No module named sklearn. This really should have just worked.

I am using Enthought's free distribution of Python (2.7.3) on a Mac OS 10.6.8 with NumPy 1.6.1 and SciPy 0.10.1. Yes, I'm aware that EPD Free comes with scikit-learn but pip should have upgraded my version so that I can actually use scikit-learn.


Solution

  • Thanks folks (see comment thread under the question)! It turns out that I have two versions of Python under my Mac's /Library/Frameworks/Python.framework directory tree: 2.7 (came with OSX) and 7.3 (installed by EPD Free).

    It turns out pip put scikit-learn under 2.7 when I really wanted it under 7.3.

    Changing directories to site-packages under the desired version of Python, and invoking pip install -t . {package-name} suffices to install package-name under the desired version of Python.

    POSTLUDE (Feb 2021): Looking back on this question from almost 9 years ago, I think I was running into a version of this XKCD comic.

    dependency management hell in python

    Nowadays, for dependency management of Python data engineering libraries like scikit, I'm happy with just using conda and pyenv.