无法导入seaborn。

3

我在导入 seaborn 时遇到了问题。最近我在电脑上安装了 "anaconda" 并尝试使用 seaborn 包。我更新了 scipynumpy。实际上,在更新 scipy 之前,Python 无法看到 seaborn。问题出在哪里?请帮助我。

Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 17:02:03) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
?         -> 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 as sns
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-ed9806ce3570> in <module>()
----> 1 import seaborn as sns

~/anaconda/lib/python2.7/site-packages/seaborn/__init__.py in <module>()
----> 1 from .rcmod import *
      2 from .utils import *
      3 from .palettes import *
      4 from .linearmodels import *
      5 from .categorical import *
~/anaconda/lib/python2.7/site-packages/seaborn/rcmod.py in <module>()
      1 """Functions that alter the matplotlib rc dictionary on the fly."""
----> 2 import numpy as np
      3 import matplotlib as mpl
      4 
      5 from . import palettes

~/anaconda/lib/python2.7/site-packages/numpy/__init__.py in <module>()
    178         return loader(*packages, **options)
    179 
--> 180     from . import add_newdocs
    181     __all__ = ['add_newdocs',
    182                'ModuleDeprecationWarning',

~/anaconda/lib/python2.7/site-packages/numpy/add_newdocs.py in <module>()
     11 from __future__ import division, absolute_import, print_function
     12 
---> 13 from numpy.lib import add_newdoc
     14 
     15 ###############################################################################

~/anaconda/lib/python2.7/site-packages/numpy/lib/__init__.py in <module>()
      6 from numpy.version import version as __version__
      7 
----> 8 from .type_check import *
      9 from .index_tricks import *
     10 from .function_base import *
~/anaconda/lib/python2.7/site-packages/numpy/lib/type_check.py in <module>()
      9            'common_type']
     10 
---> 11 import numpy.core.numeric as _nx
     12 from numpy.core.numeric import asarray, asanyarray, array, isnan, \
     13                 obj2sctype, zeros
~/anaconda/lib/python2.7/site-packages/numpy/core/__init__.py in <module>()
     12 if 'GOTOBLAS_MAIN_FREE' not in os.environ:
     13     os.environ['GOTOBLAS_MAIN_FREE'] = '1'
---> 14 from . import multiarray
     15 os.environ.clear()
     16 os.environ.update(envbak)

ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

In [2]: 

实际上问题现在已经解决了。之前我尝试使用命令 conda install -f numpy 更新 numpy,但是现在我使用 conda uninstall numpy 卸载了 numpy,然后正常地重新安装了 conda install numpy。这次它说要更新其他相关的包。之后就一切正常了。 - Bekdaulet Shukirgaliyev
所以我认为,如果在安装了anaconda之后无法导入seaborn,重新安装scipynumpy可能会有所帮助。另外,重启机器也许也可以解决问题... - Bekdaulet Shukirgaliyev
我曾经遇到过同样的问题。你需要在运行笔记本时直接将包安装到iPython中。 - Chef1075
2个回答

2

这对我在Mac上最终起作用了。

  1. 在终端中输入:iPython并按回车键
  2. 交互式Python终端应该出现了

    IPython 4.1.2 - 一个增强的交互式Python。 ? -> IPython功能介绍和概述。 %quickref -> 快速参考。 help -> Python自带的帮助系统。 object? -> 关于'object'的详细信息,请使用'object??'获取更多详细信息。

    In [1]:

  3. 输入:!pip install Seaborn

  4. 您应该会看到: 成功构建Seaborn 安装收集的软件包:Seaborn 成功安装Seaborn-0.7.1

  5. 也可以尝试(!conda而不是!pip),但!pip对我有效。然后,我尝试在iPython笔记本中运行具有“import Seaborn”的单元格,它可以工作。


0
在我的情况下,我只是重新安装了Jupyter,现在它可以正常工作了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接