【问题标题】:Conda/Python: Import Error - image not found in jupyter notebook onlyConda/Python:导入错误 - 仅在 jupyter 笔记本中找不到图像
【发布时间】:2016-12-15 17:20:24
【问题描述】:

我在jupyter 笔记本中遇到scipy.io 的导入失败。令人困惑的部分是我在 iPython 终端中没有遇到相同或任何错误,但我在标准 Python 终端中。这让我想到,不知何故,我的 jupyter 会话使用的链接路径与我的其他会话不同,但我无法弄清楚如何处理/调试/修复它。

我的问题:

  1. 有其他人遇到过这种情况或类似情况吗?
  2. jupyter 不应该在终端和笔记本会话中使用相同的库路径吗?
  3. 我在下面包含了来自conda info 的路径设置。关于这种情况是如何/为什么会发生的,是否有人会突然想到?

在 IPython 终端中

$ ipython
Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul  2 2016, 17:52:12) 
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 sys

In [2]: print(sys.executable)
/Users/jhamman/anaconda/bin/python

In [3]: import scipy.io

In [4]: 

在标准 Python 解释器中

$ python
Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul  2 2016, 17:52:12) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)
/Users/jhamman/anaconda/bin/python
>>> import scipy.io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/__init__.py", line 97, in <module>
    from .matlab import loadmat, savemat, whosmat, byteordercodes
  File "/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/matlab/__init__.py", line 13, in <module>
    from .mio import loadmat, savemat, whosmat
  File "/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/matlab/mio.py", line 12, in <module>
    from .miobase import get_matfile_version, docfiller
  File "/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/matlab/miobase.py", line 22, in <module>
    from scipy.misc import doccer
  File "/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/misc/__init__.py", line 51, in <module>
    from scipy.special import comb, factorial, factorial2, factorialk
  File "/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/special/__init__.py", line 636, in <module>
    from ._ufuncs import *
ImportError: dlopen(/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/special/_ufuncs.so, 2): Library not loaded: /usr/local/lib/libgcc_s.1.dylib
  Referenced from: /Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/special/_ufuncs.so
  Reason: image not found

在 Jupyter 笔记本中

import sys
print(sys.executable)

/Users/jhamman/anaconda/bin/python
import scipy.io
ImportError                               Traceback (most recent call last)
<ipython-input-8-05f698096e44> in <module>()
----> 1 import scipy.io

/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/__init__.py in <module>()
     95 
     96 # matfile read and write
---> 97 from .matlab import loadmat, savemat, whosmat, byteordercodes
     98 
     99 # netCDF file support

/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/matlab/__init__.py in <module>()
     11 
     12 # Matlab file read and write utilities
---> 13 from .mio import loadmat, savemat, whosmat
     14 from . import byteordercodes
     15 

/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/matlab/mio.py in <module>()
     10 from scipy._lib.six import string_types
     11 
---> 12 from .miobase import get_matfile_version, docfiller
     13 from .mio4 import MatFile4Reader, MatFile4Writer
     14 from .mio5 import MatFile5Reader, MatFile5Writer

/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/io/matlab/miobase.py in <module>()
     20     byteord = ord
     21 
---> 22 from scipy.misc import doccer
     23 
     24 from . import byteordercodes as boc

/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/misc/__init__.py in <module>()
     49 from .common import *
     50 from numpy import who, source, info as _info
---> 51 from scipy.special import comb, factorial, factorial2, factorialk
     52 
     53 import sys

/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/special/__init__.py in <module>()
    634 from __future__ import division, print_function, absolute_import
    635 
--> 636 from ._ufuncs import *
    637 
    638 from .basic import *

ImportError: dlopen(/Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/special/_ufuncs.so, 2): Library not loaded: /usr/local/lib/libgcc_s.1.dylib
  Referenced from: /Users/jhamman/anaconda/lib/python3.5/site-packages/scipy/special/_ufuncs.so
  Reason: image not found

最后一点,这是来自conda info 的转储:

$ conda info -a
Current conda install:

             platform : osx-64
        conda version : 4.1.11
    conda-env version : 2.5.2
  conda-build version : 1.21.3
       python version : 3.5.2.final.0
     requests version : 2.10.0
     root environment : /Users/jhamman/anaconda  (writable)
  default environment : /Users/jhamman/anaconda
     envs directories : /Users/jhamman/anaconda/envs
        package cache : /Users/jhamman/anaconda/pkgs
         channel URLs : https://repo.continuum.io/pkgs/free/osx-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/osx-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : None
         offline mode : False
    is foreign system : False

# conda environments:
#
root                  *  /Users/jhamman/anaconda

sys.version: 3.5.2 |Anaconda custom (x86_64)| (defaul...
sys.prefix: /Users/jhamman/anaconda
sys.executable: /Users/jhamman/anaconda/bin/python3
conda location: /Users/jhamman/anaconda/lib/python3.5/site-packages/conda
conda-build: /Users/jhamman/anaconda/bin/conda-build
conda-convert: /Users/jhamman/anaconda/bin/conda-convert
conda-develop: /Users/jhamman/anaconda/bin/conda-develop
conda-env: /Users/jhamman/anaconda/bin/conda-env
conda-index: /Users/jhamman/anaconda/bin/conda-index
conda-inspect: /Users/jhamman/anaconda/bin/conda-inspect
conda-metapackage: /Users/jhamman/anaconda/bin/conda-metapackage
conda-pipbuild: /Users/jhamman/anaconda/bin/conda-pipbuild
conda-render: /Users/jhamman/anaconda/bin/conda-render
conda-server: /Users/jhamman/anaconda/bin/conda-server
conda-sign: /Users/jhamman/anaconda/bin/conda-sign
conda-skeleton: /Users/jhamman/anaconda/bin/conda-skeleton
user site dirs: 

CIO_TEST: <not set>
CONDA_DEFAULT_ENV: <not set>
CONDA_ENVS_PATH: <not set>
DYLD_LIBRARY_PATH: <not set>
PATH: /Users/jhamman/anaconda/bin:/opt/local/bin:/opt/local/sbin
PYTHONHOME: <not set>
PYTHONPATH: <not set>

【问题讨论】:

    标签: python scipy anaconda jupyter-notebook conda


    【解决方案1】:

    这似乎是 conda 构建的一个错误:

    https://github.com/ContinuumIO/anaconda-issues/issues/899

    一位评论员 (@stuarteberg) 就该问题表示:

    最新的 scipy 最新版本(0.18.0)也有同样的问题。如果它在某种程度上有用,scipy 的 conda-forge 包不会以这种方式破坏。

    @andykitchen 发现将 scipy 降级到 0.17.0 解决了这个问题:

    是的,可以确认我也遇到了这个问题,对我来说,解决方法是也降级到 0.17.0

    conda install --force scipy=0.17.0
    

    【讨论】:

    • 谢谢!不过我有一个问题,为什么我可以从 ipython 终端导入 scipy 而不是在笔记本中?
    • 我不确定,但我的猜测是 IPython 引用了 libgcc_s 库的不同副本,因此当 scipy 尝试导入它时,它会加载缓存版本而不是硬编码版本(这会导致错误)。在您的 IPython 终端中,您可能能够跟踪用于查看它是否不同的库的路径。
    猜你喜欢
    • 2021-02-13
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    • 2019-09-16
    • 2017-02-15
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    相关资源
    最近更新 更多