提问者:小点点

我的jupyter笔记本无法始终导入anaconda模块


我不能让我的jupyter笔记本正确地导入任何模块。奇怪的是,我可以用Sublime导入Numpy,但不能导入熊猫。

我在Mac上清除了所有与python相关的内容,并重新安装了anaconda。下面是jupyter上Numpy的导入错误消息:

ImportError                               Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy

/Users/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/__init__.pyc in <module>()
    183         return loader(*packages, **options)
    184 
--> 185     from . import add_newdocs
    186     __all__ = ['add_newdocs',
    187                'ModuleDeprecationWarning',

/Users/z-wang/Library/Enthought/Canopy_64bit/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/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/__init__.py in <module>()
     16 
     17 from . import scimath as emath
---> 18 from .polynomial import *
     19 #import convertcode
     20 from .utils import *

/Users/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/polynomial.py in <module>()
     17 from numpy.lib.function_base import trim_zeros, sort_complex
     18 from numpy.lib.type_check import iscomplex, real, imag
---> 19 from numpy.linalg import eigvals, lstsq, inv
     20 
     21 class RankWarning(UserWarning):

/Users/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/__init__.py in <module>()
     49 from .info import __doc__
     50 
---> 51 from .linalg import *
     52 
     53 from numpy.testing import Tester

/Users/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/linalg.py in <module>()
     27     )
     28 from numpy.lib import triu, asfarray
---> 29 from numpy.linalg import lapack_lite, _umath_linalg
     30 from numpy.matrixlib.defmatrix import matrix_power
     31 from numpy.compat import asbytes

ImportError: dlopen(/Users/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so, 2): Library not loaded: @rpath/lib/libmkl_intel_lp64.dylib
  Referenced from: /Users/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so
  Reason: image not found

这是给熊猫的信息:

ImportError                               Traceback (most recent call last)
<ipython-input-5-d6ac987968b6> in <module>()
----> 1 import pandas

/Users/z-wang/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/__init__.py in <module>()
     11                       "pandas from the source directory, you may need to run "
     12                       "'python setup.py build_ext --inplace' to build the C "
---> 13                       "extensions first.".format(module))
     14 
     15 from datetime import datetime

ImportError: C extension: scimath not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.

共1个答案

匿名用户

删除所有与Python相关的内容是个坏主意。有些系统文件需要它。希望您没有删除错误的文件,也不必重新安装操作系统。

关于你的问题,你需要在启动jupyter笔记本之前先激活你的conda环境。

若要查看已安装的环境,请在终端窗口中键入以下内容:

conda info --envs

然后键入以下内容以激活您的环境(显然,my_env是您的环境的名称)。

source activate my_env

从这里开始,您将进入康达环境。要打开Jupyter笔记本,只需键入:

jupyter notebook

这个笔记本将链接到您的conda环境,并可以访问其中的所有模块(一旦您激活了上面的环境,请从终端键入conda list来查看它们,或者!Conda列表从笔记本内)。

为了好玩,我们将创建一个名为test_env的快速环境。

conda create -n test_env pandas jupyter notebook qtconsole matplotlib
source activate test_env
jupyter notebook  # launches your notebook

或者,要启动qt控制台:

jupyter qtconsole

虽然我们只安装了几个包,但也安装了所有链接的依赖项(包括Numpy)。这是现在的输出conda list

$ conda list
# packages in environment at /usr/local/miniconda/envs/test_env:
#
appnope                   0.1.0                    py27_0    defaults
backports-abc             0.4                       <pip>
backports.ssl-match-hostname 3.4.0.2                   <pip>
backports_abc             0.4                      py27_0    defaults
cycler                    0.10.0                   py27_0    defaults
decorator                 4.0.9                    py27_0    defaults
freetype                  2.5.5                         0    defaults
ipykernel                 4.3.1                    py27_0    defaults
ipython                   4.1.2                    py27_0    defaults
ipython-genutils          0.1.0                     <pip>
ipython_genutils          0.1.0                    py27_0    defaults
ipywidgets                4.1.1                    py27_0    defaults
jinja2                    2.8                      py27_0    defaults
jsonschema                2.4.0                    py27_0    defaults
jupyter                   1.0.0                    py27_1    defaults
jupyter-client            4.1.1                     <pip>
jupyter-console           4.1.0                     <pip>
jupyter-core              4.0.6                     <pip>
jupyter_client            4.1.1                    py27_0    defaults
jupyter_console           4.1.0                    py27_0    defaults
jupyter_core              4.0.6                    py27_0    defaults
libpng                    1.6.17                        0    defaults
markupsafe                0.23                     py27_0    defaults
matplotlib                1.5.1               np110py27_0    defaults
mistune                   0.7.1                    py27_0    defaults
mkl                       11.3.1                        0    defaults
nbconvert                 4.1.0                    py27_0    defaults
nbformat                  4.0.1                    py27_0    defaults
notebook                  4.1.0                    py27_0    defaults
numpy                     1.10.4                   py27_0    defaults
openssl                   1.0.2g                        0    defaults
pandas                    0.17.1              np110py27_0    defaults
path.py                   8.1.2                    py27_1    defaults
pexpect                   3.3                      py27_0    defaults
pickleshare               0.5                      py27_0    defaults
pip                       8.0.3                    py27_0    defaults
ptyprocess                0.5                      py27_0    defaults
pygments                  2.1.1                    py27_0    defaults
pyparsing                 2.0.3                    py27_0    defaults
pyqt                      4.11.4                   py27_1    defaults
python                    2.7.11                        0    defaults
python-dateutil           2.4.2                    py27_0    defaults
python.app                1.2                      py27_4    defaults
pytz                      2015.7                   py27_0    defaults
pyzmq                     15.2.0                   py27_0    defaults
qt                        4.8.7                         1    defaults
qtconsole                 4.1.1                    py27_0    defaults
readline                  6.2                           2    <unknown>
setuptools                20.1.1                   py27_0    defaults
simplegeneric             0.8.1                    py27_0    defaults
singledispatch            3.4.0.3                  py27_0    defaults
sip                       4.16.9                   py27_0    defaults
six                       1.10.0                   py27_0    defaults
sqlite                    3.9.2                         0    defaults
ssl_match_hostname        3.4.0.2                  py27_0    defaults
terminado                 0.5                      py27_1    defaults
tk                        8.5.18                        0    http://repo.continuum.io/pkgs/free/osx-64/tk-8.5.18-0.tar.bz2
tornado                   4.3                      py27_0    defaults
traitlets                 4.1.0                    py27_0    defaults
wheel                     0.29.0                   py27_0    defaults
zlib                      1.2.8                         0    <unknown>

完成后,停用环境。

source deactivate  # From within the terminal of the active environment.

如果要删除它,请执行以下操作:

conda env remove -n test_env