【问题标题】:Failure to import numpy in Jupyter notebook无法在 Jupyter 笔记本中导入 numpy
【发布时间】:2015-10-20 14:44:16
【问题描述】:

我是 iPython/Jupyter 的新手。 Python 技能有限,但学习。我正在尝试将 numpy 导入为 np 并获得以下信息:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-4ee716103900> in <module>()
----> 1 import numpy as np

/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/__init__.py in <module>()
    166         return loader(*packages, **options)
    167 
--> 168     from . import add_newdocs
    169     __all__ = ['add_newdocs', 'ModuleDeprecationWarning']
    170 

/Users/jmmiii/Library/Enthought/Canopy_32bit/User/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 ###############################################################################

/Users/jmmiii/Library/Enthought/Canopy_32bit/User/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 *

/Users/jmmiii/Library/Enthought/Canopy_32bit/User/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

/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/core/__init__.py in <module>()
      4 from numpy.version import version as __version__
      5 
----> 6 from . import multiarray
      7 from . import umath
      8 from . import _internal # for freeze programs

ImportError: dlopen(/Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found.  Did find:
    /Users/jmmiii/Library/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/numpy/core/multiarray.so: mach-o, but wrong architecture

我在装有 Yosemite 的 Mac 上安装了几个 python,包括 Canopy 和 Anaconda。我希望我的 Jupyter 笔记本使用 Anaconda 安装,包括与之关联的所有模块、库等。然而,似乎 jupyter 的目标是 Canopy。因此,我认为我的问题可能源于错误的链接。

问题 1:我的结论是否成立?如果没有,我可能会错过什么?

问题 2:如何将 jupyter 与 Anaconda 而不是 Canopy 直接/链接,以便仅从 anaconda 导入所有内容?

感谢大家的帮助!

【问题讨论】:

    标签: numpy import ipython importerror jupyter


    【解决方案1】:

    您可以通过运行以下命令将 PATH 设置为从 ~/anaconda/bin 目录执行 python 命令,方法是将其添加到您的 .bah_profile 中。

    export PATH="/Users/jmmiii/anaconda/bin:$PATH"
    

    或者,您可以通过编辑 ~/.bash_profile 并添加以下内容来为命令创建别名:

    alias jupyter-notebook="/Users/jmmiii/anaconda/bin/jupyter-notebook"
    

    【讨论】:

    • 谢谢约翰!我会把它藏起来以备将来参考。沮丧的是,我实际上完全卸载了 Anaconda 并重新安装了它。现在,当我加载 iPython 笔记本而不是 Jupyter 笔记本时,它可以工作。然而,这不是一个麻烦。我很欣赏上面的提示,尤其是关于别名分配的提示。
    猜你喜欢
    • 2018-07-30
    • 2020-01-04
    • 2018-11-08
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多