[英]NLTK TypeError: '<' not supported between instances of 'str' and 'int'
I have a piece of code that was working fine a while back. 我有一段代码,前一段时间工作正常。
import nltk
import pickle
from nltk.tokenize import word_tokenize
from nltk.classify import ClassifierI
from statistics import mode
I have nltk properly installed, and I wasn't getting this problem at all yesterday. 我已经正确安装了nltk,昨天我根本没有遇到这个问题。 To the best of knowledge, nothing has changed. 据我所知,没有任何改变。
Here is the complete stack trace, 这是完整的堆栈跟踪,
Traceback (most recent call last):
File "C:\Users\student\Desktop\asd.py", line 1, in <module>
import nltk
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\__init__.py", line 128, in <module>
from nltk.chunk import *
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\chunk\__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\chunk\api.py", line 13, in <module>
from nltk.parse import ParserI
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\parse\__init__.py", line 79, in <module>
from nltk.parse.transitionparser import TransitionParser
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\parse\transitionparser.py", line 21, in <module>
from sklearn.datasets import load_svmlight_file
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\__init__.py", line 57, in <module>
from .base import clone
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\base.py", line 12, in <module>
from .utils.fixes import signature
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\validation.py", line 18, in <module>
from ..utils.fixes import signature
File "C:\Users\student\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\fixes.py", line 406, in <module>
if np_version < (1, 12, 0):
TypeError: '<' not supported between instances of 'str' and 'int'
My best guess is that np_version
(the value referenced at the bottom of the stack trace) has become corrupted somehow, and is now a tuple of strings, or some other datatype that is not a tuple of ints, which is what the code is comparing it against in the line if np_version < (1, 12, 0):
. 我最好的猜测是np_version
(在堆栈跟踪底部引用的值)已经以某种方式损坏,现在是字符串的元组或其他不是int的元组的数据类型,这就是代码所比较的if np_version < (1, 12, 0):
I would suggest reinstalling nltk
, though that might not be a definite fix. 我建议重新安装nltk
,尽管这可能不是确定的解决方案。 It's possible that a version mismatch has occured in which a newer version uses a tuple of strings to store the version number. 可能发生版本不匹配的情况,其中较新的版本使用字符串元组存储版本号。 If this is so, it might be a good idea to try to install an older version of nltk
, though it's possible a reinstall will fix the problem. 如果是这样,尝试安装旧版本的nltk
可能是一个好主意,尽管重新安装可能会解决此问题。 Hope this helps! 希望这可以帮助!
Looks like you have somehow ended up with numpy
version 1.11.2rc1
. 看起来您已经以某种方式以numpy
版本1.11.2rc1
。 Scikit's fixes.py
converts this to the triple (1, 11, '2rc1')
, with the inevitable result. Scikit的fixes.py
将其转换为三元组(1, 11, '2rc1')
,结果不可避免。
Since the current version is 1.12.1, I think the solution is obvious. 由于当前版本为1.12.1,因此我认为解决方案是显而易见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.