IPython Notebook throws ImportError – IPython doesn't

天大地大妈咪最大 提交于 2019-12-12 12:26:16

问题


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

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.

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


回答1:


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

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.

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

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.



来源:https://stackoverflow.com/questions/26238004/ipython-notebook-throws-importerror-ipython-doesnt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!