6

When trying to install scikit-learn, I get the following error:

      Exception:
      Traceback (most recent call last):
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/basecommand.py", line 232, in main
          status = self.run(options, args)
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/commands/install.py", line 347, in run
          root=options.root_path,
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_set.py", line 543, in install
          requirement.uninstall(auto_confirm=True)
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_install.py", line 667, in uninstall
          paths_to_remove.remove(auto_confirm)
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_uninstall.py", line 126, in remove
          renames(path, new_path)
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/utils/__init__.py", line 316, in renames
          shutil.move(old, new)
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 300, in move
          rmtree(src)
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 252, in rmtree
          onerror(os.remove, fullname, sys.exc_info())
        File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 250, in rmtree
          os.remove(fullname)
      OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/numpy-1.8.0-py2.7.egg-info/dependency_links.txt'

How can this be resolved?

Adam_G
  • 7,337
  • 20
  • 86
  • 148
  • If you can, try and use python 3 as scikit-learn isn't supporting python 2 any more. Perhaps try using a python virtual environment (https://docs.python.org/3/tutorial/venv.html), instead of system install. This makes it easier to track dependencies and it's all self contained, no need to worry about having the right dependencies. – James McCorrie Dec 16 '20 at 15:36

8 Answers8

19

Are you the root user? Do you have admin privileges?

One way you be to do:

$ sudo pip install scikit-learn

You will need to type your password and then it should work.

Alex Huszagh
  • 13,272
  • 3
  • 39
  • 67
  • I had to upgrade pip before installing scikit-learn. Installing scikit-learn with root privileges solved the problem. Thank You. – Lalit Rane May 21 '20 at 13:02
3

One straight way to install scikit learn from scratch is following the below steps:

1) install pip from https://pypi.python.org/pypi/pip/ or upgrade in your cmd using

python -m pip install -U pip setuptools

2) run

pip install wheel

3) download the numpy, scipy & scikit learn files from http://www.lfd.uci.edu/~gohlke/pythonlibs/. (numpy+MKL & scipy modules. Check for your python version and 32 bit or 64 bit CPU.

4) run these in your command prompt:

pip install numpy-1.12.1+mkl-cp36-cp36m-win_amd64.whl

pip install scipy-0.19.0-cp36-cp36m-win_amd64.whl

pip install scikit_learn-0.18.1-cp36-cp36m-win_amd64.whl

You are ready to play with Scikit learn

5) run this in your python shell:

import numpy, scipy, sklearn

Note: I saw several articles on building from source on windows. You don't have to build from source for binary wheel files that you installed from the above link on your windows.

Aakash Saxena
  • 199
  • 3
  • 8
1
sudo pip install scikit-learn 

This would solve your issue but I would recommend you to install virtualenv for python projects.

1) Install virtualenv

[sudo] pip install virtualenv

2) Go to your project directory and create virtual environment / isolated environment for python project

virtualenv directory_name

3) Activate virtual environment

source directory_name/bin/activate

4) Install whatever you want

pip install scikit-learn
Yogesh Yadav
  • 4,557
  • 6
  • 34
  • 40
0

The problem was solved after running two commands

  1. Upgrade pip

    $/snap/pypy3/57/bin/pypy3 -m pip install --upgrade pip

  2. Install scikit-learn

    $sudo pip3 install -U scikit-learn

Lalit Rane
  • 850
  • 10
  • 16
0

Just replace PIP command with PIP3:

pip3 install numpy

pip3 install pandas

pip3 install matplotlib

pip3 install -U scikit-learn

Check this for more detalis.

Tapan Hegde
  • 1,222
  • 1
  • 8
  • 25
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 25 '21 at 05:41
0

Pls go for Python 3.8.0(Stable Version) in order to install Sklearn, it was successfully installed in my case. I had installed 3.10 and face error while trying to install Sklearn.

PS C:\Windows\system32> pip install sklearn

Collecting sklearn Using cached https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz Collecting scikit-learn (from sklearn) Downloading https://files.pythonhosted.org/packages/b8/b2/84f9ed357e35359e34ffd25381468e5120be863659ba9dac9ae161b391b0/scikit_learn-1.0.1-cp38-cp38-win_amd64.whl (7.2MB) |████████████████████████████████| 7.2MB 386kB/s Collecting joblib>=0.11 (from scikit-learn->sklearn) Using cached https://files.pythonhosted.org/packages/3e/d5/0163eb0cfa0b673aa4fe1cd3ea9d8a81ea0f32e50807b0c295871e4aab2e/joblib-1.1.0-py2.py3-none-any.whl Collecting numpy>=1.14.6 (from scikit-learn->sklearn) Downloading https://files.pythonhosted.org/packages/15/3d/70e9393b786c2464cb3060249901ace93b154495c2f2598930d06bb187f6/numpy-1.21.4-cp38-cp38-win_amd64.whl (14.0MB) |████████████████████████████████| 14.0MB 117kB/s Collecting threadpoolctl>=2.0.0 (from scikit-learn->sklearn) Using cached https://files.pythonhosted.org/packages/ff/fe/8aaca2a0db7fd80f0b2cf8a16a034d3eea8102d58ff9331d2aaf1f06766a/threadpoolctl-3.0.0-py3-none-any.whl Collecting scipy>=1.1.0 (from scikit-learn->sklearn) Downloading https://files.pythonhosted.org/packages/b9/23/8c13a8973f5f695577f396fc2a6a920d00e91727bff173c48d03d1732a78/scipy-1.7.3-cp38-cp38-win_amd64.whl (34.2MB) |████████████████████████████████| 34.2MB 218kB/s Installing collected packages: joblib, numpy, threadpoolctl, scipy, scikit-learn, sklearn Running setup.py install for sklearn ... done Successfully installed joblib-1.1.0 numpy-1.21.4 scikit-learn-1.0.1 scipy-1.7.3 sklearn-0.0 threadpoolctl-3.0.0 WARNING: You are using pip version 19.2.3, however version 21.3.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. PS C:\Windows\system32>

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 05 '21 at 23:19
-1

If you are the admin,

1) Click on “Start” and type “cmd” (without the quotations).

2)Right Click on the “cmd” icon and select “Run as Administrator”

3)Type "pip install scikit-learn" in command prompt.

-1

Actually, I was facing the same problem in windows10 recently for python3 then I try this it worked for me.

 1.  python -m pip install -U pip setuptools

 2.  pip install scikit-learn

enter image description here

Md.Rakibuz Sultan
  • 759
  • 1
  • 8
  • 13