Mysterious errors importing numpy and scipy with "knee.py"

It contains a Python source file called knee.py He overrides the regular import statement with his own hook. The code must be correct, and for built-in modules and separate file modules this is so. However, I get a weird error (both are different) when I try to import numpy with it.

 (...long stack trace) File "knee.py", line 101, in import_module m = imp.load_module(fqname, fp, pathname, stuff) TypeError: import_hook() takes at most 4 arguments (5 given) 

I do not understand why this will happen? Could it be that passed self ? None of the code in knee.py is written for the object, and I'm sure imp.load_module does not expect a self argument. Does anyone have an idea of ​​what might cause the problem? I even wrote down what was imported, and it seems that the code does not immediately get into the problem, only after it imported some other things into numpy.

In the case of scipy, I get an error message that may be related to the numpy incident:

 (...long stack trace) File "/usr/apps/python2.6/lib/python2.6/site-packages/numpy/core/__init__.py", line 10, in <module> import _sort File "knee.py", line 16, in import_hook q, tail = find_head_package(parent, name) File "knee.py", line 52, in find_head_package q = import_module(head, qname, parent) File "knee.py", line 101, in import_module m = imp.load_module(fqname, fp, pathname, stuff) ImportError: numpy.core.multiarray failed to import 

Does anyone have an idea of ​​what might be happening?

+4
source share
1 answer

SOLVED. (only for guaranteed solution for numpy and scipy package modules)

I implemented my decision. Be careful that although the code I post here works, it contains a bunch of dumb debugging statements and commented on code that can be removed, as well as a couple of other things related to what I wanted to use for this.

My solution: mknee.py

+1
source

All Articles