Error importing Seaborn module in Python

gincard picture gincard · Mar 3, 2015 · Viewed 102.7k times · Source

I am trying to import seaborn into python (using 2.7) using the following code:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
import math as math
from pylab import rcParams

%matplotlib inline

and getting the following error message:

ImportError                               Traceback (most recent call last)
<ipython-input-62-bd3d27f3b137> in <module>()
      1 import matplotlib.pyplot as plt
----> 2 import seaborn as sns
      3 import pandas as pd
      4 import numpy as np
      5 import math as math

C:\Python27\lib\site-packages\seaborn\__init__.py in <module>()
      2 from .utils import *
      3 from .palettes import *
----> 4 from .linearmodels import *
      5 from .distributions import *
      6 from .timeseries import *

C:\Python27\lib\site-packages\seaborn\linearmodels.py in <module>()
     19 from .external.six.moves import range
     20 
---> 21 from . import utils
     22 from . import algorithms as algo
     23 from .palettes import color_palette

ImportError: cannot import name utils

Can anyone please assist with this? I've tried looking through this site and also Google, but with no luck. Thanks in advance.

Answer

avp picture avp · Nov 7, 2015

I had faced the same problem. Restarting the notebook solved my problem.

If that doesn't solve the problem, you can try this

pip install seaborn

Edit

As few people have posted in the comments, you can also use

python -m pip install seaborn

Plus, as per https://bugs.python.org/issue22295 it is a better way because in this case, you can specify which version of python (python3 or python2) to use for running pip