Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error importing Seaborn module in Python

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.

like image 608
gincard Avatar asked Mar 03 '15 10:03

gincard


People also ask

How do I import my seaborn Spyder?

First open Spyder and click Tools --> Open command prompt. You should see the Command Window appear in the bottom right of your screen. Here we install the Python package seaborn as an example. This will install seaborn on your machine.


2 Answers

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

like image 63
avp Avatar answered Oct 06 '22 04:10

avp


As @avp says the bash line pip install seaborn should work I just had the same problem and and restarting the notebook didn't seem to work but running the command as jupyter line magic was a neat way to fix the problem without restarting the notebook

Jupyter Code-Cell:

%%bash pip install seaborn 
like image 22
CodingYourLife Avatar answered Oct 06 '22 04:10

CodingYourLife