python在安装的textstat中找不到模块

时间:2017-07-21 14:17:21

标签: python text module

我已经通过pip安装了textstat。 (我已经卸载并重新安装,同样的故障)。

C:\Anaconda>pip install textstat
Collecting textstat
Using cached textstat-0.3.1.tar.gz
Installing collected packages: textstat
Running setup.py install for textstat ... done
Successfully installed textstat-0.3.1

当我尝试从textstat运行任何函数时:ipython(和python)报告无法找到该模块。

您能建议解决问题的方法吗?

In [1]: from textstat import textstat
In [2]: print textstat.syllable_count("Here is some text. Here is some more.")

    AttributeError                            Traceback (most recent call last)
    <ipython-input-2-7ac2bb0cb31e> in <module>()
    ----> 1 print textstat.syllable_count("Here is some text. Here is some more.")

    AttributeError: 'module' object has no attribute 'syllable_count'

此外,ipython报告该模块存在:

In [3]: ??textstat

    Type:        module
    String form: <module 'textstat.textstat' from 'C:\Anaconda\lib\site-packages\textstat\textstat.pyc'>
    File:        c:\anaconda\lib\site-packages\textstat\textstat.py
    Source:
    from __future__ import print_function
    import pkg_resources
    import string
    import re
    import math
    import operator

    exclude = list(string.punctuation)
    easy_word_set = set([ln.strip() for ln in pkg_resources.resource_stream('textstat', 'easy_words.txt')])

    ...
    class textstatistics:
    ...
    def syllable_count(self, text):
        """
        Function to calculate syllable words in a text.
        I/P - a text
        O/P - number of syllable words
        """
    ...

1 个答案:

答案 0 :(得分:2)

textstat模块的结构似乎不太清楚。可以在syllable_count找到textstat.textstat.textstat.syllable_count函数:

import textstat
textstat.textstat.textstat.syllable_count()

projects readme中的使用部分显示以下用法示例:

from textstat.textstat import textstat
if __name__ == '__main__':
      test_data = """Playing games has always been thought to be etc.."""

  print textstat.flesch_reading_ease(test_data)
  print textstat.smog_index(test_data)
    #etc

为什么?

textstat模块具有以下结构,用于解释完整的from textstat.textstat import textstat

.
+-- textstat                    < from textstat #folder
    +-- textstat.py             <              .textstat #file

    =FILE CONTENTS=
    class textstatistics:
        def syllable_count

    textstat = textstatistics() <                        import textstat #intialised object