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. 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):
. I would suggest reinstalling nltk
, though that might not be a definite fix. 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. Hope this helps!
Looks like you have somehow ended up with numpy
version 1.11.2rc1
. Scikit's fixes.py
converts this to the triple (1, 11, '2rc1')
, with the inevitable result.
Since the current version is 1.12.1, I think the solution is obvious.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.