Invalid Syntax: import TextBlob in python 2.6.6

2.1k Views Asked by At

I have Python 2.6.6 installed

I downloaded the textblob package from Here

I installed the package using the following command

python setup.py install

Inside my site-packages I can see the following egg

textblob-0.11.1-py2.6.egg

However when I am importing the package, it gives me the following error

> from textblob import TextBlob
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/textblob-0.11.1-py2.6.egg/textblob/__init__.py", line 9, in <module>
    from .blob import TextBlob, Word, Sentence, Blobber, WordList
  File "/usr/lib/python2.6/site-packages/textblob-0.11.1-py2.6.egg/textblob/blob.py", line 28, in <module>
    import nltk
  File "/usr/lib/python2.6/site-packages/nltk-3.2.1-py2.6.egg/nltk/__init__.py", line 114, in <module>
    from nltk.collocations import *
  File "/usr/lib/python2.6/site-packages/nltk-3.2.1-py2.6.egg/nltk/collocations.py", line 38, in <module>
    from nltk.util import ngrams
  File "/usr/lib/python2.6/site-packages/nltk-3.2.1-py2.6.egg/nltk/util.py", line 1361
    d = {k: _default_to_regular(v) for k, v in d.items()}
                                 ^
SyntaxError: invalid syntax

Is there anything missing here?

UPDATE 1:

I installed successfully textblob 0.8.4

While installing NLTK 2.0.5, I am getting following error

command:

python setup.py install

Error:

`Installed /usr/lib/python2.6/site-packages/distribute-0.6.21-py2.6.egg
Traceback (most recent call last):
  File "setup.py", line 69, in <module>
    test_suite = 'nltk.test.simple',
  File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
    cmd_obj.run()
  File "build/bdist.linux-x86_64/egg/setuptools/command/install.py", line 73, in run
  File "build/bdist.linux-x86_64/egg/setuptools/command/install.py", line 101, in do_egg_install
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 345, in run

  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 565, in easy_install

  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 617, in install_item

  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 664, in process_distribution

TypeError: __init__() takes exactly 2 arguments (4 given)
`
1

There are 1 best solutions below

6
Philip Tzou On BEST ANSWER

nltk-3.2.1 doesn't support Python 2.6 (the SyntaxError is due to the fact that dictionary comprehension was not yet introduced to Python until 2.7). Either upgrading your Python to 2.7 or downgrading nltk to 2.0.5:

pip install nltk==2.0.5

Edit: After researched TextBlob's setup.py and CHANGELOG.rst files, it turns out you probably also need to downgrade TextBlob to 0.8.4 to avoid the dependency of nltk>=3.0, if you decided not to upgrade your Python.

Edit 2: To solve the setuptools error, use python distribute_setup.py instead.

Edit 3: You don't need to install nltk if you installed TextBlob <= 0.8.4. Because it contains a vendorized version of nltk.