我无法让我的jupyter笔记本正确导入任何模块。奇怪的是,我可以用Sublime导入numpy而不是pandas。
我在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.
答案 0 :(得分:2)
删除与Python相关的所有内容是错误的想法。有系统文件需要它。希望您没有删除错误的文件,并且不必重新安装操作系统。
关于你的问题,你需要先启动你的conda环境,然后再启动jupyter notebook。
要查看已安装的环境,请在终端窗口中键入以下内容:
conda info --envs
然后键入以下内容以激活您的环境(显然my_env
是您的环境的名称)。
source activate my_env
从这里开始,你就处于康茄舞的环境中。要打开Jupyter笔记本,只需输入:
jupyter notebook
此笔记本将链接到您的conda环境,并且可以访问其中的所有模块(在您已经激活您的环境以查看它们之后,从终端输入conda list
,或{{1}来自笔记本内部。)
为了好玩,我们将创建一个名为test_env的快速环境。
!conda list
或者,启动qtconsole:
conda create -n test_env pandas jupyter notebook qtconsole matplotlib
source activate test_env
jupyter notebook # launches your notebook
虽然我们只安装了一些软件包,但还安装了所有链接的依赖项(包括numpy)。现在这是jupyter qtconsole
:
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.