语法无效:在Python 2.6.6中导入TextBlob

时间:2016-12-20 06:55:51

标签: python python-2.6

我安装了Python 2.6.6

我从Here

下载了textblob软件包

我使用以下命令

安装了软件包
python setup.py install

在我的网站包中,我可以看到以下鸡蛋

textblob-0.11.1-py2.6.egg

但是,当我导入包时,它会给我以下错误

> 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

这里有什么遗漏吗?

更新1:

我成功安装了textblob 0.8.4

安装NLTK 2.0.5时,我收到以下错误

命令:

python setup.py install

错误:

`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 个答案:

答案 0 :(得分:3)

nltk-3.2.1不支持Python 2.6(SyntaxError归因于dictionary comprehension was not yet introduced to Python until 2.7)。将Python升级到2.7或将nltk降级为2.0.5

pip install nltk==2.0.5

修改:在研究了TextBlob的{​​{1}}和setup.py个文件后,您可能还need to downgrade TextBlob to 0.8.4以避免CHANGELOG.rst的依赖关系如果你决定不升级你的Python。

编辑2:要解决setuptools错误,请改用nltk>=3.0

编辑3:如果您安装了python distribute_setup.py,则无需安装nltk。因为它包含供应商版本的TextBlob <= 0.8.4