AttributeError:模块'numpy'没有属性'square'

时间:2017-11-15 14:54:34

标签: numpy matplotlib

我想使用NLTK-PorterStemmer来查找我在.txt文档中写的一些单词的词干,但总是得到相同的错误消息。似乎Stemmer的导入有问题。我更新了nltk,numpy和matplotlib并使用了Python 3.5.1 代码以:

开头
from nltk.stem.porter import PorterStemmer
from nltk.corpus import Words

我已经收到了错误:

Traceback (most recent call last):
  File "detect_wrong_words_stemming.py", line 7, in <module>
    from nltk.stem import *
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\__init__.py", line 114, in <module>
    from nltk.collocations import *
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\collocations.py", line 39, in <module>
    from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\metrics\__init__.py", line 24, in <module>
    from nltk.metrics.segmentation    import windowdiff, ghd, pk
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\metrics\segmentation.py", line 45, in <module>
    import numpy as np
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\core\__init__.py", line 38, in <module>
    from . import numeric
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\numpy\core\numeric.py", line 37, in <module>
    import pickle
  File "C:\Users\Peter\Desktop\Codes\pickle.py", line 2, in <module>
    import matplotlib.pyplot as pyplot
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\__init__.py", line 124, in <module>
    from . import cbook
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\cbook\__init__.py", line 2595, in <module>
    class _StringFuncParser(object):
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\cbook\__init__.py", line 2607, in _StringFuncPars
er
    _funcs['quadratic'] = _FuncInfo(np.square,
AttributeError: module 'numpy' has no attribute 'square'

但我不会在我的进一步代码中使用matplotlib或numpy。为什么要导入所有这些东西?

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题。如评论所述,某些文件在同一文件夹中具有无效名称将导致此问题。我的情况是我有

  

threading.py

文件夹中的

文件。