Issue with Seaborn module

When I run python program -not in codecademy environment- It always gives the error 'AttributeError: module ‘seaborn’ has no attribute ‘barplot’ . why it happens?

I’m afraid I never used seaborn for much so hopefully someone else could have more insight. If you output dir(seaborn) I assume barplot is not listed? Could it be version related (was barplot introduced at a later date)?

@szymonnowak982412090,

Can you give an example of how you are importing it and how you are using it in your program?

Thanks.

1 Like

It might be because you’re using an older version of seaborn.

When you import Seaborn, add this to the script to set the parameters:
import seaborn as sns; sns.set()

And, when you import matplot lib, do it like so:
import matplotlib.pyplot as plt

More detail on this here (scroll down to where it discusses Seaborn’s API):
https://code-examples.net/en/q/2afba6f

I also found this:
https://github.com/mwaskom/seaborn/issues/1735

It also could be related to seaborn scripts:
https://stackoverflow.com/questions/41158789/seaborn-attributeerror-module-object-has-no-attribute-set

2 Likes

Although possible, I doubt it is due to an older version of Seaborn. barplot() has been included since March 2014 (version 0.3.0). I think the more likely case is an improper import or a file/folder named seaborn. The answer in @lisalisaj’s third link is spot-on and definitely one of those “gotchas” for newer coders — don’t name your file or folder the same name as an external library you’re trying to import!

1 Like