我有一段代码在一段时间内工作正常。
import nltk
import pickle
from nltk.tokenize import word_tokenize
from nltk.classify import ClassifierI
from statistics import mode
我已经正确安装了,昨天我一直没有遇到这个问题。据我所知,一切都没有改变。
这是完整的堆栈跟踪,
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'
答案 0 :(得分:1)
我最好的猜测是np_version
(堆栈跟踪底部引用的值)已经以某种方式被破坏,现在是一个字符串元组,或者其他一些不是整数元组的数据类型,这是代码在行if np_version < (1, 12, 0):
中与之进行比较的内容。我建议重新安装nltk
,虽然这可能不是一个明确的解决方案。可能出现版本不匹配,其中较新版本使用字符串元组来存储版本号。如果是这样,那么尝试安装旧版nltk
可能是个好主意,尽管重新安装可能会解决问题。希望这有帮助!
答案 1 :(得分:1)
看起来您最终得到了numpy
版本1.11.2rc1
。 Scikit的fixes.py
会将此转换为三(1, 11, '2rc1')
,但结果不可避免。
由于当前版本是1.12.1,我认为解决方案很明显。