问题描述
我无法让jupyter笔记本正确导入任何模块.奇怪的是,我能够用Sublime导入numpy而不是pandas.
I can't get my jupyter notebook properly import any modules. The weird thing is, I am able to import numpy but not pandas with Sublime.
我在Mac上清除了所有与python相关的内容,然后重新安装了anaconda.这是jupyter上numpy的导入错误消息:
I wiped out every python related content on my Mac and re-installed anaconda. Here's the import error message for numpy on jupyter:
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.
推荐答案
删除与Python相关的所有内容都是 bad 想法.有些系统文件需要它.希望您没有删除错误的文件,也不必重新安装操作系统.
Deleting everything Python related is a bad idea. There are system files which require it. Hopefully you didn't delete the wrong files and won't have to reinstall your operating system.
关于您的问题,您需要先启动conda环境,然后再启动jupyter笔记本电脑.
Regarding your question, you need to first activate your conda environment before launching jupyter notebook.
要查看您已安装的环境,请在终端窗口中键入以下内容:
To see which environment you already have installed, type the following from a terminal window:
conda info --envs
然后键入以下内容以激活您的环境(显然,my_env
是您所处环境的名称).
Then type the following to activate your environment (obviously my_env
is the name of what ever your environment is).
source activate my_env
从这里开始,您处于conda环境中.要打开Jupyter笔记本,只需键入:
From here, you are in your conda environment. To open Jupyter notebook, just type:
jupyter notebook
此笔记本将链接到您的conda环境,并可以访问其中的所有模块(激活上方的环境以查看它们后,请从终端输入conda list
,或者从笔记本内部输入!conda list
).
This notebook will be linked to your conda environment and will have access to all modules therein (type conda list
from the terminal once you've activated your environment per above to see them, or !conda list
from within the notebook).
只是为了好玩,我们将创建一个名为test_env的快速环境.
Just for fun, we'll create a quick environment named test_env.
conda create -n test_env pandas jupyter notebook qtconsole matplotlib
source activate test_env
jupyter notebook # launches your notebook
或者,启动qtconsole:
Alternatively, to launch qtconsole:
jupyter qtconsole
尽管我们只安装了一些软件包,但所有链接的依赖项也都已安装(包括numpy).现在是conda list
:
Although we only installed a few packages, all linked dependencies are also installed (including numpy). This is now the output of 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
这篇关于我的jupyter笔记本无法始终导入anaconda模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!