Search code examples
pythonpandasscikit-learnpipminiconda

How to install and use scikit-learn in Python


Note upfront: I tried following suggestions in other threads, but so far, haven't found anything that helps (1, 2)

I received a pandas file that I would like to run on my machine. In the beginning, the code references the sklearn package.

import re
from sklearn.decomposition import FactorAnalysis
from sklearn import svm

I do, however, get the following error when running this cell:

ModuleNotFoundError: No module named 'sklearn.decomposition'

I do have the scikit_learn-0.19.0-py3.6.egg-info and sklearn packages in my Python directory, so I'm not sure why it doesn't work. I tried reinstalling it, but both...

conda install scikit-learn

...and...

pip install scikit-learn

...don't work. The former crashes my Python (pop-up window telling my it has crashed), the latter produces a bunch of error messages:

>pip install scikit-learn
Requirement already satisfied: scikit-learn in c:\programdata\...\lib\site-packages
Exception:
Traceback (most recent call last):
  File "C:\ProgramData\...\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\ProgramData\...\lib\site-packages\pip\commands\install.py", line 335, in run
    wb.build(autobuilding=True)
  File "C:\ProgramData\...\lib\site-packages\pip\wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "C:\ProgramData\...\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\ProgramData\...\lib\site-packages\pip\req\req_set.py", line 666, in _prepare_file
    check_dist_requires_python(dist)
  File "C:\ProgramData\...\lib\site-packages\pip\utils\packaging.py", line 48, in check_dist_requires_python
    feed_parser.feed(metadata)
  File "C:\ProgramData\...\lib\email\feedparser.py", line 175, in feed
    self._input.push(data)
  File "C:\ProgramData\...\lib\email\feedparser.py", line 103, in push
    self._partial.write(data)
TypeError: string argument expected, got 'NoneType'
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Any idea how I can get it to work? Thanks


Solution

  • Solved it.

    • Managed to roll-back to pip v9 using this thread.
    • Uninstalled scikit-learn (which was v0.19). Had to use Admin mode to avoid the PermissionError mentioned before
    • Installed it again (which was v0.2)

    Code works now, thanks all who contributed.