Search code examples
pythoninstallationscikit-learn

Cannot download and install scikit-learn


I am pretty new to python. I want to use KMean code, and I want to install scikit-learn or sklearn.

I used this code to attempt install these packages:

pip install -U sklearn
pip install -U scikit-learn

But I got this error:

Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_reihaneh/sklearn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-89YQB7-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_reihaneh/sklearn
Storing debug log for failure in /home/reihaneh/.pip/pip.log

What is the cause of the problem?


Solution

  • pip install -U <package>, short for pip install --upgrade <package>, will upgrade <package> to the most recent stable version in the pip repo.

    pip install <package> will install the most recent stable version of <package> in the pip repo.

    The difference is upgrading vs. installing. You want the latter.

    scikit-learn requires scipy and numpy, so here are the commands you should issue:

    pip install numpy
    pip install scipy
    pip install scikit-learn
    

    If you already have any of the dependencies, just plug in a -U between pip install and the package name.

    If you're using Python 3.x, replace pip with pip3.