语法无效:在 python 2.6.6 中导入 TextBlob
Invalid Syntax: import TextBlob in python 2.6.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)
`
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
的 setup.py
和 CHANGELOG.rst
文件后,发现您可能也 need to downgrade TextBlob
to 0.8.4
避免了对 nltk>=3.0
的依赖,如果您决定不升级 Python.
编辑 2:要解决 setuptools 错误,请改用 python distribute_setup.py
。
编辑 3:如果安装了 TextBlob <= 0.8.4
,则不需要安装 nltk
。因为它包含 nltk
.
的销售版本
我安装了 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)
`
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
的 setup.py
和 CHANGELOG.rst
文件后,发现您可能也 need to downgrade TextBlob
to 0.8.4
避免了对 nltk>=3.0
的依赖,如果您决定不升级 Python.
编辑 2:要解决 setuptools 错误,请改用 python distribute_setup.py
。
编辑 3:如果安装了 TextBlob <= 0.8.4
,则不需要安装 nltk
。因为它包含 nltk
.