Python import error: cannot import name 'six' from 'sklearn.externals'
Asked Answered
J

2

25

I'm using numpy and mlrose, and all i have written so far is:

import numpy as np
import mlrose

However, when i run it, it comes up with an error message:

 File "C:\Users\<my username>\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mlrose\neural.py", line 12, in <module>
    from sklearn.externals import six
ImportError: cannot import name 'six' from 'sklearn.externals' (C:\Users\<my username>\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sklearn\externals\__init__.py)

Any help on sorting this problem will be greatly appreciated.

Jala answered 18/5, 2020 at 10:52 Comment(2)
pip install six should install six and solve the problemFlavory
That isn't the issue. mlrose is trying to import six from sklearn, you will still get this error if you have six installed.Sumter
S
75

Solution: The real answer is that the dependency needs to be changed by the mlrose maintainers.

A workaround is:

import six
import sys
sys.modules['sklearn.externals.six'] = six
import mlrose
Sumter answered 13/6, 2020 at 2:36 Comment(5)
Newer version of mlrose with dependency fixed is now mlrose-hiive: pypi.org/project/mlrose-hiive or github.com/hiive/mlroseMarchpast
This solution worked for me with another package, skrules, giving the same error.Sesame
mlrose-hiive does not work on the tutorials. Specifically simulated_annealing in the very first tutorial does not work in the fork. The dependency may be fixed, but he broke the original without talking about it in any documentation I've found.Lexington
I made an issue for it github.com/gkhayes/mlrose/issues/59Triparted
This also works for the SkopeRules package.Biauriculate
N
2

from sklearn.externals import six is deprecated, use import six instead

Nieshanieto answered 26/5, 2020 at 23:34 Comment(3)
Doesn't seem like a very helpful response, unless you think @Jala here is a developer of mlrose (I definitely didn't get the sense from his question that he is).Iloilo
Yeah, relatively new to mlrose so I wouldn’t know what to do thereJala
This solution worked for me. Scikit-garden had the line from sklearn.externals import six and I changed it to import six. Seems to work fine now.Kept

© 2022 - 2024 — McMap. All rights reserved.