在 python 2.7 中导入 nltk 的语法无效 [英] Invalid syntax on importing nltk in python 2.7

查看:102
本文介绍了在 python 2.7 中导入 nltk 的语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我写这行时

import nltk

在 python 2.7 解释器终端中,它显示 SyntaxError:Invalid Syntax

in python 2.7 interpreter terminal it is showing SyntaxError:Invalid Syntax

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nani/.local/lib/python2.7/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.collocations import *
File "/home/nani/.local/lib/python2.7/site-packages/nltk/collocations.py", line 35, in <module>
from nltk.probability import FreqDist
File "/home/nani/.local/lib/python2.7/site-packages/nltk/probability.py", line 333
print("%*s" % (width, samples[i]), end=" ")                                      ^
SyntaxError: invalid syntax

如何解决这个问题?

推荐答案

nltk 放弃了对 Python2 的支持,尝试使用支持 python 2 的旧版本 nltk,我发现 nltk 3.0 版本支持 python 2

nltk dropped support to Python2, Try to use older versions of nltk in which it supports python 2 and I found out that nltk 3.0 version supports python 2 [edited - Thanks to user2357112 supports Monica ]

因此,尝试使用命令下载并安装以前版本的 nltk

So, Try to download and install previous versions of nltk with the command

pip install nltk==3.0

您可以更改上述情况下的版本号为 3.0,并且您可以安装合适的版本.

You can change the version number which is 3.0 in the above mentioned case and can install suitable version whichever you feels working.

它对我有用.如果有人遇到同样的问题可以尝试上述方法.

It worked for me.If anyone facing same problem can try above mentioned method.

这篇关于在 python 2.7 中导入 nltk 的语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆