python - 导入 nltk 无法理解的错误

标签 python centos nltk python-2.6 dictionary-comprehension

我刚刚在 CentOS 服务器上安装了 nltk。但是当我进入 python 并尝试导入 nltk 时,出现以下错误。

有什么想法吗?

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

最佳答案

从 3.1 版开始,NLTK 不再支持 Python < 2.7,来自 http://www.nltk.org/news.html :

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: https://github.com/nltk/nltk/blob/develop/ChangeLog

由于字典理解是 Python >=2.7 的一项功能,https://www.python.org/dev/peps/pep-0274/ , 使用 NLTK >=3.1 会在发生字典理解时导致错误。

强烈建议升级到 Python >= 2.7:https://github.com/h2oai/h2o-2/wiki/Installing-python-2.7-on-centos-6.3.-Follow-this-sequence-exactly-for-centos-machine-only

或者使用 conda 也会简化问题:https://docs.continuum.io/anaconda/install#linux-install

但如果确实需要 Python 2.6:

pip install -U nltk==3.0.5

关于python - 导入 nltk 无法理解的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36038827/

相关文章:

python - NumPy 数组 : assignment of value fails

python - 将带换行符的文本复制到剪贴板 :Python

Python NLTK FreqDist() 通过将 k、v 写入磁盘来减少内存使用?

python - 反转字符串中的每个单词

azure应用程序服务中的Python ModuleNotFoundError包

php - Vagrant phpmyadmin php 显示为纯文本问题

linux/Bash 从 curl 输出中提取变量

centos - 更改 Ambari 服务器中添加主机的主机名?

nlp - nltk wordnet lemmatizer语言是独立的吗?

python - 用python理解nltk