Skip to content Skip to sidebar Skip to footer

Invalid Syntax On Importing Nltk In Python 2.7

when I executed the below code in python 2.7 CLI import nltk it is showing the following error SyntaxError:Invalid Syntax Traceback (most recent call last): File '',

Solution 1:

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 ]

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

pip install nltk==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.


Solution 2:

The code is using the print function, which in Python 2.7 has to be enabled with

from __future__ import print_function

However, this has to appear in the module being imported, not the code importing the module. nltk appears to assume it will be imported by a Python 3 interpreter.


Post a Comment for "Invalid Syntax On Importing Nltk In Python 2.7"