3

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

4
  • 1
    Have you tried to pip unistall it and reinstall it ? Commented Nov 7, 2018 at 21:38
  • Uninstalling doesn't seem to work, I get multiple error messages. I first have to confirm, that I want to proceed with the de-installation, but then I receive this: PermissionError: [WinError 5] Access is denied: 'c:\\programdata\\...\\lib\\site-packages\\scikit_learn-0.19.0-py3.6.egg-info' -> 'C:\\Users\\...\\pip-0k0t65vd-uninstall\\programdata\\...\\lib\\site-packages\\scikit_learn-0.19.0-py3.6.egg-info' Commented Nov 7, 2018 at 21:39
  • How about pip install --user scikit-learn Commented Nov 7, 2018 at 21:44
  • This tells me the requirement is already satisfied in [path to directory] Commented Nov 7, 2018 at 21:50

4 Answers 4

4

Try running that last command to upgrade pip first?

pip install --upgrade pip

And then install scikitlearn afterwards. And possibly try this depending on what version of python you're using in your environment:

pip3 install scikit-learn
Sign up to request clarification or add additional context in comments.

5 Comments

And if you get PermissionError: [WinError 5] Access is denied: try to add the --user flag
Upgrading to the new pip worked. Even though it still gave me the old message that I was using the old version: "Successfully installed pip-18.1. You are using pip version 9.0.1...". However, when I try to install scikit-learn now, it tells me "AttributeError: module 'pip' has not attribute 'main'
Try with sudo before pip install --upgrade pip
You mean typing sudo in front of it? Doesn't seem to work
Try iterations of sudo python3 -m pip install sklearn What does pip --version output?
1

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.

Comments

0

If you are on linux...

1). download anaconda https://www.anaconda.com/download/#download

2). go to where the file is downloaded and type bash Anaconda-latest-Linux-x86_64.sh

The new anaconda already comes with scikit-learn installed.

If you need an older version of python like I did you can install that version by typing

conda install python=3.6

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.