4

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?

Anaphory
  • 6,045
  • 4
  • 37
  • 68
  • Now it works again. While I'm rebuilding some packages in the background, none of the current ones are python modules, so I can only blame the `--pylab inline` switch for my ipython, which I just removed. Still curious as to why that might lead to `scimath` not being found. – Anaphory Oct 07 '14 at 14:33

1 Answers1

2

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.

Community
  • 1
  • 1
tyleha
  • 3,319
  • 1
  • 17
  • 25
  • I doubt anything about `numpy` has changed recently, especially if you haven't updated numpy since this started happening. The answer I gave above I hoped would address your last question, namely "how do I debug this error and what does `ipython notebook` change about imports compared to cli". If you want to try and fix the problem without identifying the root cause, i'd advocate uninstalling numpy and pandas, reinstalling, and crossing your fingers. – tyleha Oct 07 '14 at 23:48
  • Ah, okay, thank you. Could you add that to your answer? It was not clear to me that you were suggesting to follow the debugging steps there, in particular because obviously `from numpy.lib import …`finds the module as …/numpy/lib/__init__.py, but the relative `from . import scimath` is not resolved, so I don't know how `os.cwd()` and `sys.path` will help. – Anaphory Oct 07 '14 at 23:55
  • The problem did indeed vanish after rebuilding a few packages, and while I cannot recreate the error now to verify this, the reason given in this answer is convincing and helps understand how such an error can occur. – Anaphory Oct 13 '14 at 16:40