CodeBird CodeBird - 1 year ago 93
Python Question

import nltk ununderstandable error

I just installed nltk on a CentOS server. But when I go into python and try to import nltk I get the following error.

Any ideas?

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/nltk/", line 114, in <module>
from nltk.collocations import *
File "/usr/lib/python2.6/site-packages/nltk/", line 38, in <module>
from nltk.util import ngrams
File "/usr/lib/python2.6/site-packages/nltk/", line 1361
d = {k: _default_to_regular(v) for k, v in d.items()}

Answer Source

Since version 3.1, NLTK drops supports for Python < 2.7, from

NLTK 3.1 released : October 2015

Add support for Python 3.5, drop support for Python 2.6, sentiment analysis package and several corpora, improved POS tagger, Twitter package, multi-word expression tokenizer, wrapper for Stanford Neural Dependency Parser, improved translation/alignment module including stack decoder, skipgram and everygram methods, Multext East Corpus and MTECorpusReader, minor bugfixes and enhancements For details see:

Since dictionary comprehension is a feature from Python >=2.7,, using NLTK >=3.1 will lead to error when a dictionary comprehension occurs.

Strongly encouraged to upgrade to Python >= 2.7:

Or using conda would simplify the problem too:

But if Python 2.6 is really necessary:

pip install -U nltk==3.0.5