-1

I've played a bit today with pyenv trying to install a certain python version as well as sklearn for data science use, but it appears I've broken it - I cannot import sklearn, though when I tried to install it using pip3/pip, I got messages showing that sklearn has already been installed.

The current situation At a jupyter notebook,

import sklearn

shows a "No module named 'sklearn' error". But when I try to install sklearn using

!pip3 install sklearn

it shows

Requirement already satisfied: sklearn in /usr/local/var/pyenv/versions/3.6.5/lib/python3.6/site-packages (0.0)

Requirement already satisfied: scikit-learn in /usr/local/var/pyenv/versions/3.6.5/lib/python3.6/site-packages (from sklearn) (0.19.1)

I've also tried to install sklearn outside jupyter notebook, and the messages are the same.

What I've done earlier today - My Mac (High Sierra) already has python 2.7, but I need python 3, so I first installed python3 by using

brew install python3
  • I installed jupyter notebook
  • At jupyter notebook, I attempted to use

    !pip3 install sklearn

to install sklearn, but got some errors, and by researching online, I've found out that it seems sklearn does not support the most recent python 3.7. - I uninstalled Python3 as well as Jupyter Notebook, before trying to get an older version of python - I tried to use brew to get an older version of python, but found out online that brew does not install a previous version easily, so I installed pyenv instead according to some online post (without actually understanding it very well) - in pyenv I installed python 2.6.5

pyenv install 2.6.5
  • I set 2.6.5 as the global python version

    pyenv global 2.6.5

  • I installed jupyter notebook again (and maybe I also installed ipython at the same time), which seems to depend on python 3.7, so from the log python 3.7 is installed (which is not what I want)

  • I ignored the fact that python 3.7 is installed, and as a matter of fact, pyenv does not reveal python 3.7 at all (so pyenv versions only show the system and the python 3.6.5)
  • I installed sklearn again
  • When I do

    pip3 install sklearn

it shows that sklearn is installed) - However, when I tried to import sklearn it shows Module not found.

Could any please point to a direction what could have gone wrong? The above list may not be very accurate as I may have repeatedly installed and uninstall things just to try out. But the more I tried, the more confused I get. I would really appreciate any help. Thank you!

  • if you have a working installation of jupyter-notebook, then in a cell run `!pip install scikit-learn` and then test installation of the package by `import sklearn` – Kumar Jul 12 '18 at 20:29
  • Yes that’s exactly what I tried. It didn’t work.. – user2579376 Jul 14 '18 at 01:15

1 Answers1

0

If you are using conda environment, this error usually comes for some modules. I faced a similar error with tensorflow. The solution is to install jupyter using conda

conda install jupyter

This fixed the error for me after I spent hours trying to uninstall and install packages again and again. The problem is that the jupyter is not coming from within the environment if you have created one.

prodigal_son
  • 116
  • 8