简体   繁体   English

seaborn AttributeError: 'module' 对象没有属性 'set'

[英]seaborn AttributeError: 'module' object has no attribute 'set'

I have anaconda2 in my windows10, and install seaborn by the command:我的 windows10 中有 anaconda2,并通过以下命令安装 seaborn:

conda install seaborn

Then I download an example from seaborn website:然后我从seaborn网站下载了一个例子:

import seaborn as sns
sns.set(style="ticks")

# Load the example dataset for Anscombe's quartet
df = sns.load_dataset("anscombe")

# Show the results of a linear regression within each dataset
sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=df,
       col_wrap=2, ci=None, palette="muted", size=4,
       scatter_kws={"s": 50, "alpha": 1})

After I run the example in my command prompt, it throws the following error:在我的命令提示符中运行该示例后,它会引发以下错误:

Traceback (most recent call last):
  File "seaborn.py", line 1, in <module>
    import seaborn as sns
  File "E:\OneDrive\seek_backward\caiwufenxi\source\seaborn.py", line 5, in   <module>
  df = sns.load_dataset("anscombe")
AttributeError: 'module' object has no attribute 'load_dataset'

Has anyone encounterd the same problem?有没有人遇到过同样的问题? How can I solve it?我该如何解决? Thanks!谢谢!

From the stacktrace it seems like your script is named seaborn.py ( File "seaborn.py", line 1, in <module> ... File "E:\\OneDrive\\seek_backward\\caiwufenxi\\source\\seaborn.py", line 5, in <module> ).seaborn.py您的脚本似乎被命名为seaborn.pyFile "seaborn.py", line 1, in <module> ... File "E:\\OneDrive\\seek_backward\\caiwufenxi\\source\\seaborn.py", line 5, in <module> )。 Try to rename it in something else (like test1.py ) and retry.尝试将其重命名为其他名称(例如test1.pytest1.py试。

You are actually trying to import your local seaborn script (which doesn't have a load_dataset function) and not the installed module.您实际上是在尝试导入本地 seaborn 脚本(没有 load_dataset 函数)而不是已安装的模块。

只需将您的脚本名称从“seaborn.py”重命名为其他名称即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM