【问题标题】:Error in nltk package in Python2.7 WidnowsPython2.7 Windows中的nltk包错误
【发布时间】:2020-06-23 18:11:40
【问题描述】:

我使用 pip 安装了 nltk,但是当我导入时,它显示以下错误。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\nltk\__init__.py", line 128, in <module>
    from nltk.collocations import *
  File "C:\Python27\lib\site-packages\nltk\collocations.py", line 35, in <module>
    from nltk.probability import FreqDist
  File "C:\Python27\lib\site-packages\nltk\probability.py", line 333
    print("%*s" % (width, samples[i]), end=" ")

【问题讨论】:

    标签: python python-2.7 pip nltk


    【解决方案1】:

    看起来问题在于 NLTK 需要 Python 3.x。注意这一行,错误是:

    print("%*s" % (width, samples[i]), end=" ")
    

    end=" " 不是有效的 Python 2.7,除非以这种方式使用 print 的 Python 文件包含语句 from __future__ import print_function

    无论如何,您都应该使用 Python 3.x,因为 Python 2.7 不受支持。

    【讨论】:

      【解决方案2】:

      nltk 3.4 支持 Python 2.7。安装:

      pip install "nltk<3.5"
      

      【讨论】:

        【解决方案3】:

        来自https://www.nltk.org/news.html

        NLTK 从 3.5 版开始正式放弃对 Python 2 的支持。 Python 2 的最后一个已知版本是:

        pip install -U nltk==3.4.5 
        

        但强烈建议您使用 Python 3。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-11-18
          • 1970-01-01
          • 2017-06-01
          • 2012-03-05
          • 1970-01-01
          • 1970-01-01
          • 2015-11-19
          相关资源
          最近更新 更多