[python-2.7] 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.

This question is related to python-2.7 python-import seaborn

The answer is


You can try using Seaborn. It works for both 2.7 as well as 3.6. You can install it by running:

pip install seaborn


Problem may not be associated with Seaborn but Utils package which may not be installed

sudo pip uninstall requests

and reinstalling, it no longer would work at all. Luckily, dnf install python-requests fixed the whole thing...

Also check for utils package is installed or not

You can install package using

sudo pip install utils

Check this link Python ImportError: cannot import name utils


If your python version is 2.+, you can type below code to the terminal :

pip install seaborn

if python version is 3+, type below:

pip3 install seaborn

pip install seaborn 

is also solved my problem in windows 10


  1. delete package whl file in 'C:\Users\hp\Anaconda3\Lib\site-packages'
  2. pip uninstlal scipy and seaborn
  3. pip install scipy nd seaborn agaian

it worked for 4, win10, anaconda


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

I had the same problem and I am using iPython. pip or conda by itself did not work for me but when I use !conda it did work.

!conda install seaborn

I solved the same importing problem reinstalling to seaborn package with

conda install -c https://conda.anaconda.org/anaconda seaborn

by typing the command on a Windows command console Afterwards I could then import seaborn successfully when I launched the IPython Notebook via on Anaconda launcher.

On the other failed way launching the IPython Notebook via Anaconda folder did not work for me.


I got same issue with Seaborn. I uninstalled python, anaconda and reinstalled anaconda 4.1.1 with python 3.6. After that installed seaboarn again

conda install seaborn

And it worked. If you are still facing issue, I would recommend you doing this.


I have the same problem and I solved it and the explanation is as follow:

If the Seaborn package is not installed in anaconda, you will not be able to update it, namely, if in the Terminal we type: conda update seaborn

it will fail showing: "PackageNotFoundError: Package not found: 'seaborn' Package 'seaborn' is not installed in /Users/yifan/anaconda"

Thus we need to install seaborn in anaconda first by typing in Terminal: conda install -c https://conda.anaconda.org/anaconda seaborn

Then the seaborn will be fetched and installed in the environment of anaconda, namely in my case, /Users/yifan/anaconda

Once this installation is done, we will be able to import seaborn in python.

Side note, to check and list all discoverable environments where python is installed in anaconda, type in Terminal: conda info --envs


I would definitely recommend that you install Anaconda and then use the "pip install seaborn" command from the Lab Jupyter IDE. It should work. It seems that the package is already pre-installed on Lab Jupyter.


It seams that missing dependency of python-dev, install python-dev and then try to install seaborn, if you are using Ubuntu:

sudo apt-get install python-dev -y
pip install seaborn

it's a problem with the scipy package, just pip uninstall scipy and reinstall it


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


I solved this problem by looking at sys.path (the path for finding modules) while in ipython and noticed that I was in a special environment (because I use conda).

so i went to my terminal and typed "source activate py27" is my python 2.7 environment. and then "conda update seaborn", restarted my jupyter kernel, and then all was good.


Examples related to python-2.7

Numpy, multiply array with scalar Not able to install Python packages [SSL: TLSV1_ALERT_PROTOCOL_VERSION] How to create a new text file using Python Could not find a version that satisfies the requirement tensorflow Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support Display/Print one column from a DataFrame of Series in Pandas How to calculate 1st and 3rd quartiles? How can I read pdf in python? How to completely uninstall python 2.7.13 on Ubuntu 16.04 Check key exist in python dict

Examples related to python-import

Python: 'ModuleNotFoundError' when trying to import module from imported package ImportError: libSM.so.6: cannot open shared object file: No such file or directory Relative imports - ModuleNotFoundError: No module named x ModuleNotFoundError: What does it mean __main__ is not a package? Reading file using relative path in python project What does from __future__ import absolute_import actually do? Why does using from __future__ import print_function breaks Python2-style print? Automatically create requirements.txt Error importing Seaborn module in Python Why can't Python import Image from PIL?

Examples related to seaborn

How to create a stacked bar chart for my DataFrame using seaborn? Edit seaborn legend Seaborn Barplot - Displaying Values Add Legend to Seaborn point plot How to add title to seaborn boxplot Make the size of a heatmap bigger with seaborn Fine control over the font size in Seaborn plots for academic papers How to set the range of y-axis for a seaborn boxplot? How to save a Seaborn plot into a file Label axes on Seaborn Barplot