pandas IPython Notebook 抛出 ImportError – IPython 不会
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26238004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IPython Notebook throws ImportError – IPython doesn't
提问by Anaphory
I am trying to import pandasin an ipython (2.2.0, running python 3.3.5) notebook in my browser, which fails with
我试图import pandas在浏览器中的 ipython(2.2.0,运行 python 3.3.5)笔记本中失败
[...]
/usr/local/lib/python3.3/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 ###############################################################################
/usr/local/lib/python3.3/site-packages/numpy/lib/__init__.py in <module>()
15 from .ufunclike import *
16
---> 17 from . import scimath as emath
18 from .polynomial import *
19 #import convertcode
ImportError: cannot import name scimath
However, in both pure python and non-notebook ipython, import pandasand the problematic line of from numpy.lib import add_newdocrun without a problem, and the file /usr/local/lib/python3.3/site/site-packages/numpy/lib/scimath.pyexists and has the same permissions and creation date as the __init__.pyin the same directory.
但是,在纯python和非笔记本ipython中,import pandas有问题的那一行from numpy.lib import add_newdoc运行都没有问题,而且文件/usr/local/lib/python3.3/site/site-packages/numpy/lib/scimath.py存在并且__init__.py与同一目录下的文件具有相同的权限和创建日期。
How do I debug this error? What does ipython notebookchange about imports as compared to cli ipython?
如何调试此错误?ipython notebook与 cli 相比,进口有什么变化ipython?
采纳答案by tyleha
See this previous question and answer - https://stackoverflow.com/a/15622021/1766755.
请参阅之前的问答 - https://stackoverflow.com/a/15622021/1766755。
A key difference between the IPy notebook and CLI is the default behavior of the os.pathvar, as well as the notebook setting notebook_dir.
IPy notebook 和 CLI 之间的一个主要区别是os.pathvar的默认行为,以及 notebook 设置notebook_dir。
Obviously in the IPy notebook, pandas is not finding the scimath module. If you look closely at the traceback, you'll see the line
显然在 IPy 笔记本中,pandas 没有找到 scimath 模块。如果你仔细查看回溯,你会看到这条线
17 from . import scimath as math
This is a relative path import, the . signifying a request to import a module from the same directory. Depending on where the CLI is begun vs where you tell IPython to thinkit's running from, this could be the cause of numpy not finding scimath. I could be wrong, but it's happened to me before.
这是一个相对路径导入,. 表示请求从同一目录导入模块。根据 CLI 的开始位置与您告诉 IPython认为它运行的位置,这可能是 numpy 找不到 scimath 的原因。我可能是错的,但它以前发生在我身上。

