smilebomb smilebomb - 1 year ago 37
Bash Question

Can't find module that exists

From the cli I enter the python shell via


I then take a look at my import search path:

import sys
print '\n'.join(sys.path)

/other paths...

So I know
is in my python search path.

Continuing inside the python shell:

import imp

ImportError: No module named

Hmm, the
tells me that
is on the python search path, but the
module can't seem to find it.

Continuing further inside the python shell:

from import baz

<module '' from '/path/to/a/package/'>

Yes, I have directories
under my main directory
. Why would
not be able to locate my package?

Answer Source

imp.find_module does not handle names with dots. From the documentation:

This function does not handle hierarchical module names (names containing dots).

It also points out a solution:

In order to find P.M, that is, submodule M of package P, use find_module() and load_module() to find and load package P, and then use find_module() with the path argument set to P.__path__. When P itself has a dotted name, apply this recipe recursively.