seaborn: iPython: "ImportError: No module named seaborn"

This might be a duplicate of #801 but I don’t think so.

I’m trying to import seaborn into iPython, however I get this error:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import seaborn;
from sklearn.linear_model import LinearRegression
from scipy import stats
import pylab as pl
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-e3d40abd657b> in <module>()
      2 import numpy as np
      3 import matplotlib.pyplot as plt
----> 4 import seaborn;
      5 from sklearn.linear_model import LinearRegression
      6 from scipy import stats

ImportError: No module named seaborn

I can import seaborn into my python shell, but not into iPython.

Suggestions?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Thanks! I’m just getting into learning how to use iPython (Jupyter).

Would you have any advice on how to point it to the same python installation?

This is a relatively common problem with Python (not specific to seaborn) that can arise in cases where you have multiple installations of Python on your machine. Typically, it means that the command you used to install seaborn (i.e. pip) is pointing at a different installation from your python / ipython / jupyter command.

On a UNIX system, you can check where commands are coming from using which pip, which ipython, etc. These should be in the same directory. I imagine there is an analogous process on Windows machines but I don’t know what it is.

The best way to solve the problem is to tidy up your environment, i.e. by defining your PATH variable so that there’s only one Python installation living on it.

There are also two ways that I know of to install packages that are less likely to encounter this problem:

  • You can invoke pip as python -m pip install seaborn (or use python3 if that’s the name of the binary on your system)
  • In (newer versions of) Jupyter, there is a %pip magic function that you can run from inside the Jupyter session/notebook