【问题标题】:Python NLTK align import errorPython NLTK对齐导入错误
【发布时间】:2016-07-07 09:02:15
【问题描述】:

我收到一个奇怪的 NLTK 对齐模块导入错误:

$ python2 --version
Python 2.7.10
$ pip2 freeze | grep nltk
nltk==3.2
$ python2
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> from nltk.align import AlignedSent
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named align

如您所见,我为 python 2.7 安装了 nltk 3.2。我可以直接导入nltk。但是,我无法访问align 模块。

我知道我使用的 import 语句是正确的,因为我直接从 the official documentation 获取它。此外,我查看了the interface changes from NLTK 2 to NLTK 3 并没有提到align 模块。


为什么会发生这种情况,我可以做些什么来解决这个问题?

【问题讨论】:

    标签: python nltk python-import python-module


    【解决方案1】:

    从 NLTK 版本 3.2 开始,align 模块一直是 renamed to translate。因此使用:

    from nltk.translate import AlignedSent
    

    【讨论】:

    • 谢谢!这对我有帮助
    • 好的,但是为什么 NLTK 3.5b1 文档中的示例仍然使用 from nltk.align import AlignedSent ?我已经安装了 NLTK 3.4.5,并且我一直在该文档的“HOWTO”部分中遇到不起作用的示例。你知道如何解决这个问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    相关资源
    最近更新 更多