【发布时间】:2015-05-03 22:24:45
【问题描述】:
我正在尝试使用以下代码将 seaborn 导入 python(使用 2.7):
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
并收到以下错误消息:
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
有人可以帮忙吗?我试过浏览这个网站和谷歌,但没有运气。提前致谢。
【问题讨论】:
-
有文件
C:\Python27\lib\site-packages\seaborn\utils.py吗?可能不是,所以您可能安装了不正确的seaborn版本(太旧?)。 -
感谢 Evert - 此文件存在。我有最新版本的 seaborn(2014 年 11 月),它都与我的 python 下载捆绑在一起。是不是这个 seaborn 版本不兼容 2.7?
-
那样的话,我不知道;我绝对无法重现您的问题。您可以从最简单的 Python shell(不是 IPython,只是 Python)尝试以下操作:
>>> import seaborn? -
有时卸载/安装有效,但这也可能是 IPython 的本地配置问题,卸载 IPython 时可能不会删除这些文件。您是否在 IPython 中单独尝试过相同的
import seaborn?如果它在那里失败,那么 IPython 的配置有问题;尽管回溯显示的相对导入语法看起来是正确的。 -
魔术 ;-)。有时,未重新编译的已编译
*.pyc文件可能会搞砸事情,尽管这在这里没有多大意义。清除所有*.pyc会有所帮助,但在这里,我真的不知道。
标签: python-2.7 python-import seaborn