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.

smci
  • 32,567
  • 20
  • 113
  • 146
Jack
  • 451
  • 1
  • 5
  • 10

2 Answers2

73

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
smci
  • 32,567
  • 20
  • 113
  • 146
bcattle
  • 12,115
  • 6
  • 62
  • 82
  • 3
    Newer version of mlrose with dependency fixed is now mlrose-hiive: https://pypi.org/project/mlrose-hiive/ or https://github.com/hiive/mlrose – Burrito Mar 08 '21 at 16:22
  • This solution worked for me with another package, skrules, giving the same error. – cfelix Sep 07 '21 at 19:52
  • 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. – Brian Stallter Feb 17 '22 at 17:21
  • I made an issue for it https://github.com/gkhayes/mlrose/issues/59 – pellucidcoder Mar 01 '22 at 04:13
  • This also works for the SkopeRules package. – Guilherme Noronha Jun 15 '22 at 21:51
2

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

LevG
  • 177
  • 6
  • 2
    Doesn't seem like a very helpful response, unless you think @Jack here is a developer of `mlrose` (I definitely didn't get the sense from his question that he is). – Marcel Besixdouze Jun 08 '20 at 23:18
  • Yeah, relatively new to mlrose so I wouldn’t know what to do there – Jack Jun 14 '20 at 10:35
  • 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. – Lfppfs Mar 01 '23 at 16:19