Search code examples
pythonpython-3.xscikit-learnpipsklearn-pandas

sklearn 'preprocessor' submodule not available when importing


I've found a few other posts such as this one complaining about not being able to import several things regarding sklearn, but I've tried every proposed solution (which comes down to: pip3 install -U and apt install in every situation, also on posts asking about something other than preprocessor), but it still doesn't help.

The problem I'm having is:

>>> import sklearn
>>> sklearn.__version__
'0.20.3'
>>> sklearn.preprocessor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'sklearn' has no attribute 'preprocessor'
>>> from sklearn import preprocessor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'preprocessor'

The output when installing the supposedly correct packages is as follows:

$ pip3 install -U scikit-learn
Collecting scikit-learn
  Using cached https://files.pythonhosted.org/packages/5e/82/c0de5839d613b82bddd088599ac0bbfbbbcbd8ca470680658352d2c435bd/scikit_learn-0.20.3-cp36-cp36m-manylinux1_x86_64.whl
Collecting numpy>=1.8.2 (from scikit-learn)
  Using cached https://files.pythonhosted.org/packages/35/d5/4f8410ac303e690144f0a0603c4b8fd3b986feb2749c435f7cdbb288f17e/numpy-1.16.2-cp36-cp36m-manylinux1_x86_64.whl
Collecting scipy>=0.13.3 (from scikit-learn)
  Using cached https://files.pythonhosted.org/packages/7f/5f/c48860704092933bf1c4c1574a8de1ffd16bf4fde8bab190d747598844b2/scipy-1.2.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy, scipy, scikit-learn
Successfully installed numpy-1.16.2 scikit-learn-0.20.3 scipy-1.2.1

or:

$ sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 49 not upgraded.

As you can see, the package should be installed correctly in two different ways, but it still doesn't work. I've also tried uninstalling one of those (in case they interfered with each other), but that didn't solve anything either.

Does anyone know why this is not working for me? If I need to provide with any other information about my installation I'd be happy to provide it.


Solution

  • This happened to me as well before, Here is the solution

    import sklearn.preprocessing # or from sklearn import preprocessing