AttributeError:模块'numpy.polynomial'没有属性'polynomial'

时间:2019-08-18 18:18:37

标签: python numpy scikit-learn

我尝试从文档中运行一个scikit-learn简单示例,但是我不断收到以下错误消息

AttributeError: module 'numpy.polynomial' has no attribute 'polynomial'

我在SO中发现了两个错误相同的问题,但都建议再次删除并安装numpy。但是,这并不能解决我的问题。

当我尝试使用下面的两个代码中的任何一个进行聚类时,都会出现上述错误

from sklearn.cluster import DBSCAN
import numpy as np
X = np.array([[1, 2], [2, 2], [2, 3], 8, 7], [8, 8], [25, 80]])
clustering = DBSCAN(eps=3, min_samples=2).fit(X)

from sklearn.cluster import AgglomerativeClustering
import numpy as np
X = np.array([[1, 2], [1, 4], [1, 0], [4, 2], [4, 4], [4, 0]])
clustering = AgglomerativeClustering().fit(X)

我的require.txt文件如下

alabaster==0.7.12
appnope==0.1.0
arrow==0.14.3
asn1crypto==0.24.0
astroid==2.2.5
attrs==19.1.0
Babel==2.7.0
backcall==0.1.0
binaryornot==0.4.4
bleach==3.1.0
blis==0.2.4
boto==2.49.0
boto3==1.9.162
botocore==1.12.163
bz2file==0.98
certifi==2019.6.16
cffi==1.12.3
chardet==3.0.4
Click==7.0
cloudpickle==1.2.1
cookiecutter==1.6.0
cryptography==2.7
cymem==1.31.2
cytoolz==0.9.0.1
decorator==4.4.0
defusedxml==0.6.0
dill==0.2.9
docutils==0.15.1
el-core-news-md==2.1.0a7
el-core-news-sm==2.1.0a7
entrypoints==0.3
et-xmlfile==1.0.1
future==0.17.1
idna==2.8
imagesize==1.1.0
ipykernel==5.1.1
ipython==7.6.1
ipython-genutils==0.2.0
isort==4.3.21
jdcal==1.4.1
jedi==0.13.3
Jinja2==2.10.1
jinja2-time==0.2.0
jmespath==0.9.4
joblib==0.13.2
jsonschema==2.6.0
jupyter-client==5.3.1
jupyter-core==4.5.0
keyring==18.0.0
lazy-object-proxy==1.4.1
MarkupSafe==1.1.1
mccabe==0.6.1
mistune==0.8.4
mkl-fft==1.0.14
mkl-random==1.0.2
mkl-service==2.0.2
msgpack==0.5.6
murmurhash==0.28.0
nbconvert==5.5.0
nbformat==4.4.0
nltk==3.4.4
numpy==1.16.4
numpydoc==0.9.1
openpyxl==2.6.2
packaging==19.0
pandocfilters==1.4.2
parso==0.5.0
pexpect==4.7.0
pickleshare==0.7.5
plac==0.9.6
poyo==0.5.0
preshed==1.0.1
prompt-toolkit==2.0.9
psutil==5.6.3
ptyprocess==0.6.0
pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
Pygments==2.4.2
pylint==2.3.1
pyOpenSSL==19.0.0
pyparsing==2.4.0
pyrsistent==0.14.11
PySocks==1.7.0
python-dateutil==2.8.0
pytz==2019.1
pyzmq==18.0.0
QtAwesome==0.5.7
qtconsole==4.5.2
QtPy==1.8.0
regex==2018.7.11
requests==2.22.0
rope==0.14.0
s3transfer==0.2.0
scikit-learn==0.21.3
scipy==1.3.1
six==1.12.0
smart-open==1.8.4
snowballstemmer==1.9.0
spacy-nightly==2.1.0a13
Sphinx==2.1.2
sphinxcontrib-applehelp==1.0.1
sphinxcontrib-devhelp==1.0.1
sphinxcontrib-htmlhelp==1.0.2
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.2
sphinxcontrib-serializinghtml==1.1.3
spyder==3.3.6
spyder-kernels==0.5.1
srsly==0.0.7
termcolor==1.1.0
testpath==0.4.2
thinc==7.0.8
toolz==0.10.0
tornado==6.0.3
tqdm==4.32.1
traitlets==4.3.2
ujson==1.35
unicodedata2==12.0.0
urllib3==1.24.2
wasabi==0.2.2
wcwidth==0.1.7
webencodings==0.5.1
whichcraft==0.6.0
wrapt==1.10.11
wurlitzer==1.0.2

修改

完全追溯错误

runfile('/Scripts/test.py', wdir='/Scripts')
Traceback (most recent call last):

  File "<ipython-input-14-59f5ade3a302>", line 1, in <module>
    runfile('/Scripts/test.py', wdir='/Scripts')

  File "/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Scripts/test.py", line 1, in <module>
    from sklearn.cluster import DBSCAN

  File "/lib/python3.7/site-packages/sklearn/__init__.py", line 76, in <module>
    from .base import clone

  File "/lib/python3.7/site-packages/sklearn/base.py", line 16, in <module>
    from .utils import _IS_32BIT

  File "/lib/python3.7/site-packages/sklearn/utils/__init__.py", line 13, in <module>
    from scipy.sparse import issparse

  File "/lib/python3.7/site-packages/scipy/sparse/__init__.py", line 229, in <module>
    from .base import *

  File "/lib/python3.7/site-packages/scipy/sparse/base.py", line 7, in <module>
    from scipy._lib._numpy_compat import broadcast_to

  File "/lib/python3.7/site-packages/scipy/_lib/_numpy_compat.py", line 201, in <module>
    polyvalfromroots = np.polynomial.polynomial.polyvalfromroots

AttributeError: module 'numpy.polynomial' has no attribute 'polynomial'

1 个答案:

答案 0 :(得分:1)

尝试安装较新的pip更新numpy 17.0,安装的是16.4,很奇怪,重新安装了numpy。 从我的点子: scikit学习== 0.21.3 numpy == 1.17.0