0
votes

So I am trying to use Ipython notebook with Anaconda (Windows10). I got into anaconda cmd and create a new environment TryThis. I install Seaborn in this environment. And then I run Ipython command in the conda cmd.

   conda create --name TryThis python=2
   activate TryThis
   conda install seaborn
   ipython

When I run

   import seaborn as sns

in this it executes allright.

However if I exit this and then run

   ipython notebook

in the conda cmd and go on to do the import in an ipython notebook in browser, it throws error

---------------------------------------------------------------------------
 ImportError                               Traceback (most recent call last)
 <ipython-input-1-ed9806ce3570> in <module>()
  ----> 1 import seaborn as sns

 ImportError: No module named seaborn

I do not understand what is going wrong. If Seaborn is in this anaconda environment and I initiated Ipython notebook in this environment and Ipython in console can recognize it, why doesn't the notebook ?

What I might be doing is something blatantly incorrect, but I just started out with using anaconda !

2
did you install ipython by executing conda install ipython? You cannot use your default one - it will not see the packages installed in your environment. - cel

2 Answers

0
votes

Type:

!conda info

in your notebook. Check what default environment says. It should be the same as in your session in which you can import seaborn.

0
votes

First try

conda install seaborn

Restart your Jupyther notebook and see if it works.

If you have already installed Seaborn using conda, make sure that when you start Jupyter notebook, it uses the Anaconda path. It typically prints out the path in terminal when you start Jupyter notebook.

I have run into this issue earlier, and the reason was that my Jupyter notebook was using the path from .graphlab (a tool by Dato/Turi/Apple). So even though I had installed Seaborn correctly with conda insatall seaborn , the Jupyter notebook was not able to find the library.

You may not have the exact same issue, but from what you're describing, it sounds like your issue is somewhat similar.

If you're able to import seaborn, when you run ipython from terminal; and if you're not able to import seaborn from Jupyter notebook, then follow these steps:

  • From your terminal, find the ipython path with

    which ipython

  • Now, Start Jupyter notebook and pay attention (in your terminal) to which path your Jupyter notebook is using.
  • If you're not able to import seaborn in Jupyter notebook, most likely that path is different from the ipython path that you saw earlier.

Once you have confirmed that this is the issue, then all you need to do is make Jupyter use correct path. There are various ways to do it. My way was to get rid of my installation of Anaconda entirely, and install jupyer notebook using pip.

pip install jupyter

As long as you have installed your libraries (NumPy, SciPy, Pandas, Seaborn, etc) using pip, your jupyter will be able to import these libraries. In my opinion, pip install * is the way to go for anything Python.