简体   繁体   中英

Error in nltk package in Python2.7 Widnows

I installed nltk using pip but when I import, it shows the below error.

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=" ")

Looks like the problem is that NLTK requires Python 3.x. Notice this line, where the error is:

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

The end=" " is not valid Python 2.7, unless the Python file that uses print in that way contains the statement from __future__ import print_function .

In any case, you should really use Python 3.x anyway, now that Python 2.7 is unsupported.

nltk 3.4 supports Python 2.7. To install:

pip install "nltk<3.5"

From https://www.nltk.org/news.html

NLTK officially drops Python 2 support as of version 3.5. Last known version for Python 2 is:

pip install -U nltk==3.4.5 

But you are strongly advised to use Python 3.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM