Cannot import seaborn in Jupyter notebook

6,304 views
Skip to first unread message

spagodo

unread,
Jun 9, 2016, 4:26:35 PM6/9/16
to Project Jupyter
Hi, i'm having trouble importing seaborn in a jupyter notebook. Please help

$conda info
Current conda install:

             platform : linux-64
        conda version : 4.0.8
  conda-build version : 1.20.3
       python version : 3.5.1.final.0
     requests version : 2.10.0
     root environment : /home/user/anaconda3  (writable)
  default environment : /home/user/anaconda3
     envs directories : /home/user/anaconda3/envs
        package cache : /home/user/anaconda3/pkgs
         channel URLs : https://repo.continuum.io/pkgs/free/linux-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/linux-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : None
    is foreign system : False


$ which python
~/anaconda3/bin/python

$which python3
~/anaconda3/bin/python3


$python3
Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Dec  7 2015, 11:16:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>import seaborn
>>>

(this works)


$which ipython
~/anaconda3/bin/ipython
$ipython
Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Dec  7 2015, 11:16:01)
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import seaborn

In [2]:

(this works)



Now, if I start a jupyter-notebook:

In [1]: import seaborn

ImportError                               Traceback (most recent call last)
<ipython-input-1-085c0287ecb5> in <module>()
----> 1 import seaborn

ImportError: No module named 'seaborn'




Thomas Kluyver

unread,
Jun 9, 2016, 4:32:18 PM6/9/16
to Project Jupyter
On 9 June 2016 at 22:26, spagodo <spa...@gmail.com> wrote:
Hi, i'm having trouble importing seaborn in a jupyter notebook. Please help

Your notebook kernel is probably running on a different Python, or in a different environment, from Python at the command line. Check sys.executable to see which Python it's running on and sys.path to see where it's looking for imports.

Other devs: This is the second question along these lines today. See ongoing discussion at  https://github.com/ipython/ipython/issues/9517 .

spagodo

unread,
Jun 9, 2016, 5:01:27 PM6/9/16
to Project Jupyter
import sys
sys.executable
'/home/user/anaconda2/envs/py35/bin/python3'


Aha! even though I commented anaconda2 out in my bashrc, somehow jupyter is still being run from there.

$rm -rf ~/home/user/anaconda2
$reboot
$conda remove jupyter
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ....
Solving package specifications: .
Package plan for package removal in environment /home/user/anaconda3:

The following packages will be REMOVED:

    jupyter: 1.0.0-py35_3

Proceed ([y]/n)? y

Unlinking packages ...
[      COMPLETE      ]|#########################################################################################################| 100%


$conda install jupyter
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ....
Solving package specifications: .........

Package plan for installation in environment /home/user/anaconda3:

The following NEW packages will be INSTALLED:

    jupyter: 1.0.0-py35_3

Proceed ([y]/n)? y

Linking packages ...
[      COMPLETE      ]|#########################################################################################################| 100%


$which jupyter-notebook
~/anaconda3/bin/jupyter-notebook




Ok, ready to go?
$jupyter-notebook
~/anaconda3/bin/jupyter-notebook
[user@129-79-58-70 Jupyter Notebooks]$ jupyter-notebook
[I 16:58:20.181 NotebookApp] Serving notebooks from local directory: /home/user/Jupyter Notebooks
[I 16:58:20.181 NotebookApp] 0 active kernels
[I 16:58:20.181 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
[I 16:58:20.181 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

(click New -> Python3 )

[I 16:59:18.787 NotebookApp] Creating new notebook in
[E 16:59:19.430 NotebookApp] Failed to run command:
    ['/home/user/anaconda2/envs/py35/bin/python3', '-m', 'ipykernel', '-f', '/run/user/1000/jupyter/kernel-44278f0f-2789-408d-bcd5-aafc489805f5.json']






Matthias Bussonnier

unread,
Jun 9, 2016, 5:05:58 PM6/9/16
to jup...@googlegroups.com
On Thu, Jun 9, 2016 at 2:01 PM, spagodo <spa...@gmail.com> wrote:

>
> (click New -> Python3 )
>
> [I 16:59:18.787 NotebookApp] Creating new notebook in
> [E 16:59:19.430 NotebookApp] Failed to run command:
> ['/home/user/anaconda2/envs/py35/bin/python3', '-m', 'ipykernel', '-f',
> '/run/user/1000/jupyter/kernel-44278f0f-2789-408d-bcd5-aafc489805f5.json']



<snip> env/py35/... <snip>

You are trying to run the Python3 kernel from a non existing env,
install ipykernel (should be installed already), and setup the kernelspec:

$ python -m ipykernel install

--
M

Thomas Kluyver

unread,
Jun 9, 2016, 5:16:10 PM6/9/16
to Project Jupyter
On 9 June 2016 at 23:01, spagodo <spa...@gmail.com> wrote:
[E 16:59:19.430 NotebookApp] Failed to run command:
    ['/home/user/anaconda2/envs/py35/bin/python3'

OK, you've installed a kernelspec (metadata telling IPython how to start a kernel) at some point while using that Anaconda installation. You can see where it is by running:

jupyter kernelspec list

Then either delete that kernelspec (it defaults to running in the same environment as Jupyter if it can import 'ipykernel'), or update the kernel.json file to point to a valid Python.

Thomas

spagodo

unread,
Jun 9, 2016, 5:25:10 PM6/9/16
to Project Jupyter

Thanks, python -m ipykernel install worked, all problems solved.

I guess whenever I installed the new anaconda it didn't change the kernelspec, I just didn't notice until now because everything worked.

Anyway, thanks again  for the quick responses.

S.L.

unread,
Mar 7, 2020, 9:21:11 AM3/7/20
to Project Jupyter
No module named seaborn

I understand OP already had a solution. 
This may be an alternative solution to anyone who got this error in Jupyter Notebook.
For the record so anyone may search:

Deactivating the virtual environment and then $pip3 install seaborn probably solved this problem for me. 
Maybe because Jupyter notebook may not depend on this virtual environment.

Remember to restart terminal and launch new jupyter browser session.

Reply all
Reply to author
Forward
0 new messages