TypeError: unorderable types: str() < int()

后端 未结 1 460
刺人心
刺人心 2021-01-14 01:23

I was using python 3.5 and all packages were the following versions

numpy-1.12.0b1+mkl-cp35-cp35m-win_amd64

scikit_learn-0.18.1-cp35-cp35m-win_amd64

scipy-         


        
相关标签:
1条回答
  • 2021-01-14 01:36

    Your version of numpy is numpy-1.12.0b1. That "b1" is causing the problem. If you look at sklearn/utils/fixes.py you see there's a parse_version function which tries to make everything ints:

    def _parse_version(version_string):
        version = []
        for x in version_string.split('.'):
            try:
                version.append(int(x))
            except ValueError:
                # x may be of the form dev-1ea1592
                version.append(x)
        return tuple(version)
    
    np_version = _parse_version(np.__version__)
    

    but in the case of "0b1" we'll take the ValueError path. So this line

     if np_version < (1, 12, 0):
    

    compares

    >>> (1, 12, '0b1') < (1, 12, 0)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unorderable types: str() < int()
    

    which won't work. While this is definitely a bug on their part, the easiest solution is to change your version of numpy (say, by switching back to 1.11.2). But if you want to keep your current version of numpy, you could just edit fixes.py manually to change

    if np_version < (1, 12, 0):
    

    into

    if np_version < (1, 12):
    

    so that it won't try to compare 0 with "0b1", but will return False instead.

    0 讨论(0)
提交回复
热议问题