Notebook引发ImportError

Notebook引发ImportError

本文介绍了IPython Notebook引发ImportError – IPython没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在浏览器的ipython(2.2.0,正在运行python 3.3.5)笔记本中import pandas,但操作失败

I am trying to import pandas in an ipython (2.2.0, running python 3.3.5) notebook in my browser, which fails with

[...]

/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

但是,在纯python和非笔记本ipython中,import pandas和有问题的from numpy.lib import add_newdoc行都可以正常运行,并且文件/usr/local/lib/python3.3/site/site-packages/numpy/lib/scimath.py存在并且具有与在同一目录中.

However, in both pure python and non-notebook ipython, import pandas and the problematic line of from numpy.lib import add_newdoc run without a problem, and the file /usr/local/lib/python3.3/site/site-packages/numpy/lib/scimath.py exists and has the same permissions and creation date as the __init__.py in the same directory.

如何调试此错误?与cli ipython相比,ipython notebook的进口有什么变化?

How do I debug this error? What does ipython notebook change about imports as compared to cli ipython?

推荐答案

请参阅此先前的问题和解答- https://stackoverflow. com/a/15622021/1766755 .

See this previous question and answer - https://stackoverflow.com/a/15622021/1766755.

IPy笔记本电脑和CLI之间的主要区别在于os.path var的默认行为以及笔记本电脑设置notebook_dir.

A key difference between the IPy notebook and CLI is the default behavior of the os.path var, as well as the notebook setting notebook_dir.

很明显,在IPy笔记本中,pandas找不到scimath模块.如果您仔细观察一下追溯,您将看到该行

Obviously in the IPy notebook, pandas is not finding the scimath module. If you look closely at the traceback, you'll see the line

17 from . import scimath as math

这是相对路径导入,.表示请求从同一目录导入.根据CLI的开始位置以及您告诉IPython 思考的运行位置,这可能是numpy无法找到scimath的原因.我可能是错的,但这是我以前发生过的事情.

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 think it's running from, this could be the cause of numpy not finding scimath. I could be wrong, but it's happened to me before.

这篇关于IPython Notebook引发ImportError – IPython没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 22:23