Error importing Seaborn module in Python

2019-03-24 05:19发布

问题:

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.

回答1:

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


回答2:

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


回答3:

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


回答4:

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



回答5:

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.



回答6:

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.



回答7:

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.



回答8:

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



回答9:

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


回答10:

pip install seaborn 

is also solved my problem in windows 10



回答11:

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


回答12:

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



回答13:

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